結果

問題 No.1572 XI
ユーザー tokusakuraitokusakurai
提出日時 2021-06-27 14:20:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 659 ms / 2,000 ms
コード長 2,484 bytes
コンパイル時間 2,084 ms
コンパイル使用メモリ 207,500 KB
実行使用メモリ 285,584 KB
最終ジャッジ日時 2023-09-07 17:47:49
合計ジャッジ時間 10,850 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 75 ms
61,328 KB
testcase_05 AC 346 ms
139,408 KB
testcase_06 AC 263 ms
167,108 KB
testcase_07 AC 11 ms
7,660 KB
testcase_08 AC 42 ms
143,596 KB
testcase_09 AC 137 ms
69,304 KB
testcase_10 AC 87 ms
112,548 KB
testcase_11 AC 21 ms
11,808 KB
testcase_12 AC 101 ms
50,116 KB
testcase_13 AC 28 ms
13,844 KB
testcase_14 AC 87 ms
52,312 KB
testcase_15 AC 11 ms
13,608 KB
testcase_16 AC 68 ms
43,176 KB
testcase_17 AC 7 ms
6,388 KB
testcase_18 AC 17 ms
62,380 KB
testcase_19 AC 76 ms
150,012 KB
testcase_20 AC 56 ms
96,716 KB
testcase_21 AC 279 ms
173,836 KB
testcase_22 AC 328 ms
135,428 KB
testcase_23 AC 5 ms
5,676 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 94 ms
259,400 KB
testcase_35 AC 70 ms
256,652 KB
testcase_36 AC 204 ms
263,636 KB
testcase_37 AC 652 ms
273,232 KB
testcase_38 AC 406 ms
268,620 KB
testcase_39 AC 299 ms
270,964 KB
testcase_40 AC 131 ms
249,684 KB
testcase_41 AC 403 ms
262,484 KB
testcase_42 AC 659 ms
266,324 KB
testcase_43 AC 277 ms
261,964 KB
testcase_44 AC 125 ms
285,432 KB
testcase_45 AC 481 ms
285,584 KB
testcase_46 AC 484 ms
285,500 KB
testcase_47 AC 66 ms
285,504 KB
testcase_48 AC 406 ms
285,480 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:85:26: 警告: ‘nr’ may be used uninitialized [-Wmaybe-uninitialized]
   85 |             nk = (nr >= 3? 1 : 0);
      |                  ~~~~~~~~^~~~~~~~
main.cpp:49:33: 備考: ‘nr’ はここで定義されています
   49 |     int ni, nx, ny, nt, nd, nk, nr;
      |                                 ^~
main.cpp:86:39: 警告: ‘nd’ may be used uninitialized [-Wmaybe-uninitialized]
   86 |             ni = (nx*W+ny)*72+nt*12+nd*2+nk;
      |                                     ~~^~
main.cpp:49:25: 備考: ‘nd’ はここで定義されています
   49 |     int ni, nx, ny, nt, nd, nk, nr;
      |                         ^~
main.cpp:86:33: 警告: ‘nt’ may be used uninitialized [-Wmaybe-uninitialized]
   86 |             ni = (nx*W+ny)*72+nt*12+nd*2+nk;
      |                               ~~^~~
main.cpp:49:21: 備考: ‘nt’ はここで定義されています
   49 |     int ni, nx, ny, nt, nd, nk, nr;
      |                     ^~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define each(e, v) for(auto &e: v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct io_setup{
    io_setup(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

int main(){
    int H, W; cin >> H >> W;

    int N = H*W;
    int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; sx--, sy--, gx--, gy--;

    vector<string> S(H);
    rep(i, H) cin >> S[i];

    vector<int> dp(N*72, -1);

    queue<int> que;
    int s = (sx*W+sy)*72+2;
    que.emplace(s);
    dp[s] = 0;

    int i, memo, x, y, t, d, k, r;
    int ni, nx, ny, nt, nd, nk, nr;
    vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};

    while(!empty(que)){
        i = que.front(); que.pop();
        memo = i;
        k = memo%2, memo/=2;
        d = memo%6, memo/=6;
        t = memo%6, memo/=6;
        y = memo%W, memo/=W;
        x = memo;
        r = (12-t-d)%3+3*k;

        if(x == gx && y == gy && t == 0){
            cout << dp[i] << '\n';
            return 0;
        }
        
        rep(j, 4){
            nx = x+dx[j], ny = y+dy[j];
            if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if(S[nx][ny] == '#') continue;

            if(j == 0){
                nt = (d+3)%6, nd = t, nr = r;
            }
            if(j == 1){
                nt = (r+3)%6, nd = d, nr = t;
            }
            if(j == 2){
                nt = d, nd = (t+3)%6, nr = r;
            }
            if(j == 3){
                nt = r, nd = d, nr = (t+3)%6;
            }

            nk = (nr >= 3? 1 : 0);
            ni = (nx*W+ny)*72+nt*12+nd*2+nk;

            if(dp[ni] == -1){
                dp[ni] = dp[i]+1;
                que.emplace(ni);
            }
        }
    }

    cout << "-1\n";
}
0