結果

問題 No.2646 Cycle Maze
ユーザー shinnshinn
提出日時 2024-02-13 21:56:20
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 319 ms / 2,500 ms
コード長 1,681 bytes
コンパイル時間 2,878 ms
コンパイル使用メモリ 258,664 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-09-29 10:59:54
合計ジャッジ時間 6,389 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

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;
    pair<int,int> s, g;
    cin >> s.first >> s.second >> g.first >> g.second;
    --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';
        }
    }
    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