結果

問題 No.1572 XI
ユーザー tokusakuraitokusakurai
提出日時 2021-06-27 14:20:40
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,484 bytes
コンパイル時間 12,712 ms
コンパイル使用メモリ 263,568 KB
最終ジャッジ日時 2025-01-22 14:17:40
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40 TLE * 5
権限があれば一括ダウンロードができます
コンパイルメッセージ
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