結果

問題 No.323 yuki国
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-04-19 17:56:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 269 ms / 5,000 ms
コード長 2,007 bytes
コンパイル時間 1,358 ms
コンパイル使用メモリ 152,304 KB
実行使用メモリ 13,440 KB
最終ジャッジ日時 2023-09-10 21:26:35
合計ジャッジ時間 4,523 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
13,164 KB
testcase_01 AC 6 ms
13,196 KB
testcase_02 AC 6 ms
13,136 KB
testcase_03 AC 6 ms
13,104 KB
testcase_04 AC 6 ms
13,196 KB
testcase_05 AC 6 ms
13,268 KB
testcase_06 AC 6 ms
13,164 KB
testcase_07 AC 6 ms
13,104 KB
testcase_08 AC 167 ms
13,176 KB
testcase_09 AC 51 ms
13,284 KB
testcase_10 AC 6 ms
13,152 KB
testcase_11 AC 6 ms
13,100 KB
testcase_12 AC 6 ms
13,112 KB
testcase_13 AC 49 ms
13,132 KB
testcase_14 AC 165 ms
13,136 KB
testcase_15 AC 45 ms
13,136 KB
testcase_16 AC 93 ms
13,196 KB
testcase_17 AC 58 ms
13,164 KB
testcase_18 AC 7 ms
13,116 KB
testcase_19 AC 108 ms
13,292 KB
testcase_20 AC 7 ms
13,256 KB
testcase_21 AC 269 ms
13,440 KB
testcase_22 AC 24 ms
13,204 KB
testcase_23 AC 259 ms
13,156 KB
testcase_24 AC 10 ms
13,248 KB
testcase_25 AC 60 ms
13,136 KB
testcase_26 AC 10 ms
13,196 KB
testcase_27 AC 217 ms
13,416 KB
testcase_28 AC 60 ms
13,144 KB
testcase_29 AC 58 ms
13,280 KB
testcase_30 AC 6 ms
13,160 KB
testcase_31 AC 6 ms
13,124 KB
testcase_32 AC 6 ms
13,116 KB
testcase_33 AC 6 ms
13,116 KB
testcase_34 AC 6 ms
13,264 KB
testcase_35 AC 6 ms
13,156 KB
testcase_36 AC 7 ms
13,108 KB
testcase_37 AC 5 ms
13,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int H, W;
    int A, sy, sx;
    int B, gy, gx;
    vector<string> F;
    void input() {
        cin >> H >> W;
        cin >> A >> sy >> sx;
        cin >> B >> gy >> gx;
        F.clear(); F.resize(H);
        cin >> F;
    }

    const int INF = 1<<28;

    struct S {
        int y, x, c;
        S(int y, int x, int c) : y(y), x(x), c(c) {}
    };

    const int dy[] = {0, -1, 0, 1};
    const int dx[] = {-1, 0, 1, 0};

    const int MAX_H = 50;
    const int MAX_W = 50;

    void solve() {
        static bool D[MAX_H][MAX_W][4000];
        memset(D, 0, sizeof(D));

        queue<S> Q;
        Q.push(S(sy, sx, A));
        D[sy][sx][A] = 1;
        while (not Q.empty()) {
            S cur = Q.front(); Q.pop();
            if (cur.y == gy && cur.x == gx && cur.c == B) {
                cout << "Yes" << endl;
                return;
            }
            for (int i = 0; i < 4; i++) {
                int ny = cur.y + dy[i];
                int nx = cur.x + dx[i];
                if (ny < 0 || ny >= H) continue;
                if (nx < 0 || nx >= W) continue;
                int nc = cur.c + (F[ny][nx] == '.' ? -1 : 1);
                if (nc <= 0) continue;
                if (nc >= 4000) continue;
                if (not D[ny][nx][nc]) {
                    D[ny][nx][nc] = 1;
                    Q.push(S(ny, nx, nc));
                }
            }
        }
        cout << "No" << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}
0