結果

問題 No.2646 Cycle Maze
ユーザー shinnshinnshinnshinn
提出日時 2024-02-13 22:03:45
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 376 ms / 2,500 ms
コード長 1,945 bytes
コンパイル時間 2,922 ms
コンパイル使用メモリ 259,972 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-25 17:30:51
合計ジャッジ時間 6,585 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 1 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 1 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 1 ms
6,676 KB
testcase_23 AC 1 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 9 ms
6,676 KB
testcase_26 AC 16 ms
6,676 KB
testcase_27 AC 47 ms
6,676 KB
testcase_28 AC 7 ms
6,676 KB
testcase_29 AC 8 ms
6,676 KB
testcase_30 AC 10 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 17 ms
6,676 KB
testcase_34 AC 38 ms
6,676 KB
testcase_35 AC 24 ms
6,676 KB
testcase_36 AC 17 ms
6,676 KB
testcase_37 AC 17 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 13 ms
6,676 KB
testcase_40 AC 2 ms
6,676 KB
testcase_41 AC 17 ms
6,676 KB
testcase_42 AC 9 ms
6,676 KB
testcase_43 AC 3 ms
6,676 KB
testcase_44 AC 8 ms
6,676 KB
testcase_45 AC 103 ms
6,676 KB
testcase_46 AC 113 ms
6,676 KB
testcase_47 AC 15 ms
6,676 KB
testcase_48 AC 79 ms
6,676 KB
testcase_49 AC 98 ms
6,676 KB
testcase_50 AC 217 ms
6,676 KB
testcase_51 AC 369 ms
6,676 KB
testcase_52 AC 375 ms
6,676 KB
testcase_53 AC 374 ms
6,676 KB
testcase_54 AC 376 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

inline bool in_grid(int i, int j, int h, int w) {
    return 0 <= i && i < h && 0 <= j && j < w;
}

const int di[] = {0, 1, -1, 0, 0};
const int dj[] = {0, 0, 0, 1, -1};

void solve(){
    int h, w, t;
    cin >> h >> w >> t;
    assert(1 <= h && h <= 200);
    assert(1 <= w && w <= 200);
    assert(1 <= t && t <= 600);

    pair<int,int> s, g;
    cin >> s.first >> s.second >> g.first >> g.second;

    assert(1 <= s.first <= h);
    assert(1 <= s.second <= w);
    assert(1 <= g.first <= h);
    assert(1 <= g.second <= w);

    --s.first; --s.second; --g.first; --g.second;
    vector<vector<char>> a(h, vector<char>(w));
    for(int i = 0;i < h; ++i){
        for(int j = 0;j < w; ++j){
            cin >> a[i][j];
            a[i][j] -= '0';
            assert(0 <= a[i][j] <= 9);
        }
    }
    vector b = a;
    vector ok(h, vector<bool>(w));
    ok[s.first][s.second] = true;
    for(int ii = 1;ii < t; ++ii){
        for(int i = 0;i < h; ++i){
            for(int j = 0;j < w; ++j){
                b[i][j] = (b[i][j] - 1) % (a[i][j] + 1);
                if(b[i][j] < 0)b[i][j] += a[i][j] + 1;
            }
        }
        vector nok(h, vector<bool>(w));
        for(int i = 0;i < h; ++i){
            for(int j = 0;j < w; ++j){
                if(!ok[i][j])continue;
                for(int d = 0;d < 5; ++d){
                    int ni = i + di[d];
                    int nj = j + dj[d];
                    if(!in_grid(ni, nj, h, w))continue;
                    if(b[ni][nj] == 0)continue;
                    nok[ni][nj] = true;
                }
            }
        }

        ok = move(nok);

        if(ok[g.first][g.second]){
            cout << "Yes" << endl;
            return;
        }
    }

    cout << "No" << endl;
}


int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout<<fixed<<setprecision(12);
    solve();
    return 0;
}
0