結果

問題 No.2646 Cycle Maze
ユーザー kokosei
提出日時 2024-02-25 21:07:04
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 455 ms / 2,500 ms
コード長 1,884 bytes
コンパイル時間 2,797 ms
コンパイル使用メモリ 246,992 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-09-29 11:17:26
合計ジャッジ時間 7,012 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int H, W, T;
int gx, gy;
int A[220][220], B[220][220];
bool dp[210][210], ndp[210][210];
int dx[5] = {0, 1, 0, -1};
int dy[5] = {1, 0, -1, 0};
template<typename A, int N, typename T>
void Fill(A (&arr)[N], const T &val){
    fill((T*)arr, (T*)(arr + N), val);
}
bool inside(int x, int y){
    return 0 <= x && x < H && 0 <= y && y < W;
}
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> H >> W >> T;
    {
        int x, y; cin >> x >> y;
        x--, y--;
        dp[x][y] = true;
    }
    cin >> gx >> gy;
    gx--, gy--;
    for(int i = 0;i < H;i++){
        string s; cin >> s;
        for(int j = 0;j < W;j++){
            int v = s[j] - '0';
            A[i][j] = B[i][j] = v;
        }
    }
    for(int t = 1;t < T;t++){
        if(dp[gx][gy])break;
        //cout << t << " # \n";
        for(int x = 0;x < H;x++){
            for(int y = 0;y < W;y++){
                //cout << dp[x][y] << " \n"[y + 1 == W];
            }
        }
        for(int x = 0;x < H;x++){
            for(int y = 0;y < W;y++){
                B[x][y] = (A[x][y] + B[x][y]) % (A[x][y] + 1);
                //cout << B[x][y] << " \n"[y + 1 == W];
            }
        }
        for(int x = 0;x < H;x++){
            for(int y = 0;y < W;y++){
                for(int d = 0;d < 5;d++){
                    int nx = x + dx[d], ny = y + dy[d];
                    if(!inside(nx, ny))continue;
                    if(B[nx][ny] == 0)continue;
                    ndp[nx][ny] |= dp[x][y];
                }
            }
        }
        swap(dp, ndp);
        Fill(ndp, 0);
        for(int x = 0;x < H;x++){
            for(int y = 0;y < W;y++){
                //cout << dp[x][y] << " \n"[y + 1 == W];
            }
        }
    }
    cout << (dp[gx][gy] ? "Yes\n" : "No\n");
    return 0;
}
0