結果

問題 No.1572 XI
ユーザー tokusakuraitokusakurai
提出日時 2021-06-27 14:20:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 812 ms / 2,000 ms
コード長 2,484 bytes
コンパイル時間 2,308 ms
コンパイル使用メモリ 209,332 KB
実行使用メモリ 285,568 KB
最終ジャッジ日時 2024-06-25 11:35:57
合計ジャッジ時間 13,685 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 104 ms
61,568 KB
testcase_05 AC 420 ms
139,392 KB
testcase_06 AC 359 ms
167,296 KB
testcase_07 AC 12 ms
7,552 KB
testcase_08 AC 115 ms
143,744 KB
testcase_09 AC 165 ms
69,444 KB
testcase_10 AC 143 ms
112,512 KB
testcase_11 AC 23 ms
11,904 KB
testcase_12 AC 124 ms
50,304 KB
testcase_13 AC 33 ms
14,080 KB
testcase_14 AC 109 ms
52,352 KB
testcase_15 AC 14 ms
13,696 KB
testcase_16 AC 86 ms
43,136 KB
testcase_17 AC 8 ms
6,400 KB
testcase_18 AC 45 ms
62,720 KB
testcase_19 AC 154 ms
150,016 KB
testcase_20 AC 104 ms
96,768 KB
testcase_21 AC 374 ms
173,952 KB
testcase_22 AC 408 ms
135,680 KB
testcase_23 AC 6 ms
5,888 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 224 ms
259,584 KB
testcase_35 AC 200 ms
256,768 KB
testcase_36 AC 344 ms
263,680 KB
testcase_37 AC 805 ms
273,408 KB
testcase_38 AC 548 ms
268,800 KB
testcase_39 AC 446 ms
271,100 KB
testcase_40 AC 252 ms
249,960 KB
testcase_41 AC 551 ms
262,656 KB
testcase_42 AC 812 ms
266,368 KB
testcase_43 AC 417 ms
262,144 KB
testcase_44 AC 266 ms
285,568 KB
testcase_45 AC 633 ms
285,568 KB
testcase_46 AC 640 ms
285,440 KB
testcase_47 AC 210 ms
285,568 KB
testcase_48 AC 559 ms
285,568 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:85:26: warning: 'nr' may be used uninitialized [-Wmaybe-uninitialized]
   85 |             nk = (nr >= 3? 1 : 0);
      |                  ~~~~~~~~^~~~~~~~
main.cpp:49:33: note: 'nr' was declared here
   49 |     int ni, nx, ny, nt, nd, nk, nr;
      |                                 ^~
main.cpp:86:39: warning: 'nd' may be used uninitialized [-Wmaybe-uninitialized]
   86 |             ni = (nx*W+ny)*72+nt*12+nd*2+nk;
      |                                     ~~^~
main.cpp:49:25: note: 'nd' was declared here
   49 |     int ni, nx, ny, nt, nd, nk, nr;
      |                         ^~
main.cpp:86:33: warning: 'nt' may be used uninitialized [-Wmaybe-uninitialized]
   86 |             ni = (nx*W+ny)*72+nt*12+nd*2+nk;
      |                               ~~^~~
main.cpp:49:21: note: 'nt' was declared here
   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