夢追い人

"It takes a dreamer to make a dream come true."―Vincent Willem van Gogh

これを時間の無駄という

なにやってんのおれ
一完だし
今日のはだいたいやるだけだけど実装が厳し目の問題です

A

#include <iostream>
using namespace std;
int n, res;
string w;
int main() {
    cin>>n;
    res=0;
    for (int i=0; i<n; i++) {
        cin>>w;
        if (i==n-1) {
            if (w=="TAKAHASHIKUN."||w=="Takahashikun."||w=="takahashikun.") res++;
        } else if (w=="TAKAHASHIKUN"||w=="Takahashikun"||w=="takahashikun") res++;
    }
    cout<<res<<endl;
}

B

#include <cstdio>
#include <iostream>
using namespace std;
int dx=0, dy=0;
int x, y;
string W;
string c[10];
int main() {
    cin>>y>>x>>W;
    if (W=="R") dy=1;
    if (W=="L") dy=-1;
    if (W=="U") dx=-1;
    if (W=="D") dx=1;
    if (W=="RU") {
        dx=-1; dy=1;
    }
    if (W=="RD") {
        dx=1; dy=1;
    }
    if (W=="LU") {
        dx=-1; dy=-1;
    }
    if (W=="LD") {
        dx=1; dy=-1;
    }
    for (int i=0; i<9; i++) cin>>c[i];
    string res="";
    x--; y--;
    while (res.length()<4) {
        res.push_back(c[x][y]);
        x+=dx; y+=dy;
        if (x<0||x>8) {x-=2*dx; dx*=-1;}
        if (y<0||y>8) {y-=2*dy; dy*=-1;}
    }
    cout<<res<<endl;
}

C

#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
using namespace std;
typedef pair<int, int> P;
int h, w;
string c[500];
int d[500][500];
int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1};
int main() {
    cin>>h>>w;
    int sx=0, sy=0, gx=0, gy=0;
    for (int i=0; i<h; i++) {
        cin>>c[i];
        for (int j=0; j<w; j++) {
            if (c[i][j]=='s') {
                sx=i; sy=j;
            }
            if (c[i][j]=='g') {
                gx=i; gy=j;
            }
        }
    }
    memset(d, -1, sizeof(d));
    queue<pair<int, P> > que;
    que.push(make_pair(0,P(sx,sy)));
    d[sx][sy]=0;
    while (!que.empty()) {
        int x=que.front().second.first, y=que.front().second.second;
        int cnt=que.front().first;
        que.pop();
        if (d[x][y]<cnt) continue;
        for (int i=0; i<4; i++) {
            int nx=x+dx[i], ny=y+dy[i];
            if (nx>=0&&nx<h&&ny>=0&&ny<w) {
                int nc=cnt+(c[nx][ny]=='#');
                if (nc>=3) continue;
                if (d[nx][ny]==-1||d[nx][ny]>cnt) {
                    que.push(make_pair(nc,P(nx,ny)));
                    d[nx][ny]=nc;
                }
            }
        }
    }
    if (d[gx][gy]!=-1&&d[gx][gy]<3) puts("YES");
    else puts("NO");
}