結果

問題 No.2646 Cycle Maze
ユーザー kokoseikokosei
提出日時 2024-02-25 21:07:04
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 540 ms / 2,500 ms
コード長 1,884 bytes
コンパイル時間 2,855 ms
コンパイル使用メモリ 247,244 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-25 21:07:14
合計ジャッジ時間 8,155 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 24 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 2 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 3 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 6 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 21 ms
6,676 KB
testcase_26 AC 30 ms
6,676 KB
testcase_27 AC 86 ms
6,676 KB
testcase_28 AC 13 ms
6,676 KB
testcase_29 AC 18 ms
6,676 KB
testcase_30 AC 20 ms
6,676 KB
testcase_31 AC 5 ms
6,676 KB
testcase_32 AC 4 ms
6,676 KB
testcase_33 AC 38 ms
6,676 KB
testcase_34 AC 77 ms
6,676 KB
testcase_35 AC 43 ms
6,676 KB
testcase_36 AC 38 ms
6,676 KB
testcase_37 AC 43 ms
6,676 KB
testcase_38 AC 4 ms
6,676 KB
testcase_39 AC 25 ms
6,676 KB
testcase_40 AC 3 ms
6,676 KB
testcase_41 AC 31 ms
6,676 KB
testcase_42 AC 14 ms
6,676 KB
testcase_43 AC 5 ms
6,676 KB
testcase_44 AC 14 ms
6,676 KB
testcase_45 AC 182 ms
6,676 KB
testcase_46 AC 216 ms
6,676 KB
testcase_47 AC 40 ms
6,676 KB
testcase_48 AC 161 ms
6,676 KB
testcase_49 AC 193 ms
6,676 KB
testcase_50 AC 368 ms
6,676 KB
testcase_51 AC 508 ms
6,676 KB
testcase_52 AC 540 ms
6,676 KB
testcase_53 AC 512 ms
6,676 KB
testcase_54 AC 536 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

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