結果

問題 No.1572 XI
ユーザー 沙耶花沙耶花
提出日時 2021-06-27 13:24:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,028 ms / 2,000 ms
コード長 2,822 bytes
コンパイル時間 4,514 ms
コンパイル使用メモリ 268,120 KB
実行使用メモリ 29,016 KB
最終ジャッジ日時 2023-09-07 17:36:40
合計ジャッジ時間 25,218 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 212 ms
11,656 KB
testcase_05 AC 490 ms
18,304 KB
testcase_06 AC 593 ms
24,448 KB
testcase_07 AC 14 ms
4,376 KB
testcase_08 AC 508 ms
22,284 KB
testcase_09 AC 241 ms
25,272 KB
testcase_10 AC 393 ms
25,608 KB
testcase_11 AC 32 ms
4,380 KB
testcase_12 AC 173 ms
22,868 KB
testcase_13 AC 42 ms
10,280 KB
testcase_14 AC 179 ms
17,008 KB
testcase_15 AC 40 ms
4,632 KB
testcase_16 AC 146 ms
20,768 KB
testcase_17 AC 15 ms
12,116 KB
testcase_18 AC 215 ms
23,160 KB
testcase_19 AC 533 ms
24,304 KB
testcase_20 AC 341 ms
25,680 KB
testcase_21 AC 618 ms
22,508 KB
testcase_22 AC 482 ms
22,240 KB
testcase_23 AC 12 ms
8,056 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 931 ms
26,940 KB
testcase_35 AC 916 ms
27,740 KB
testcase_36 AC 936 ms
27,308 KB
testcase_37 AC 980 ms
27,984 KB
testcase_38 AC 956 ms
28,004 KB
testcase_39 AC 966 ms
28,256 KB
testcase_40 AC 888 ms
26,872 KB
testcase_41 AC 946 ms
27,208 KB
testcase_42 AC 951 ms
27,948 KB
testcase_43 AC 942 ms
28,020 KB
testcase_44 AC 1,020 ms
29,016 KB
testcase_45 AC 1,028 ms
28,944 KB
testcase_46 AC 1,022 ms
28,988 KB
testcase_47 AC 29 ms
28,888 KB
testcase_48 AC 1,023 ms
28,916 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:180:42: 警告: ‘dd’ may be used uninitialized [-Wmaybe-uninitialized]
  180 |                         if(dis[yy][xx][dd]!=Inf)continue;
      |                            ~~~~~~~~~~~~~~^
main.cpp:173:29: 備考: ‘dd’ はここで定義されています
  173 |                         int dd;
      |                             ^~

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

struct dice{
	/*
	Top,Left,
	Front,Back,
	Right,Bottom
	*/
	vector<int> number = {1,2,3,4,5,6};
	vector<vector<int>> states;
	
	void findStates(){
		states.clear();
		rep(i,4){
			rep(j,4){
				states.push_back(number);
				rotateClockwise(1);
			}
			rotateFront(1);
		}
		rotateLeft(1);
		rep(i,4){
			states.push_back(number);
			rotateClockwise(1);
		}
		rotateLeft(2);
		rep(i,4){
			states.push_back(number);
			rotateClockwise(1);
		}
		rotateLeft(1);
	}
	
	void set(vector<int> numbers){
		number = numbers;
	}
	
	void rotateFront(int n = 1){
		n = (n%4+4)%4;
		rep(i,n){
			int t = top();
			top() = back();
			back() = bottom();
			bottom() = front();
			front() = t;
		}
	}
	
	void rotateLeft(int n = 1){
		n = (n%4+4)%4;
		rep(i,n){
			int t = top();
			top() = right();
			right() = bottom();
			bottom() = left();
			left() = t;
		}
	}
	
	void rotateClockwise(int n = 1){
		n = (n%4+4)%4;
		rep(i,n){
			int t = front();
			front() = right();
			right() = back();
			back() = left();
			left() = t;
		}
	}
	
	int& top(){
		return number[0];
	}
	
	int& bottom(){
		return number[5];
	}
	
	int& front(){
		return number[2];
	}
	
	int& back(){
		return number[3];
	}
	
	int& left(){
		return number[1];
	}
	
	int& right(){
		return number[4];
	}
	
	const int& top()const{
		return number[0];
	}
	
	const int& bottom()const{
		return number[5];
	}
	
	const int& front()const{
		return number[2];
	}
	
	const int& back()const{
		return number[3];
	}
	
	const int& left()const{
		return number[1];
	}
	
	const int& right()const{
		return number[4];
	}
	
};

int dis[1005][1005][6];

int main(){
	
	int H,W;
	cin>>H>>W;
	
	int sx,sy,gx,gy;
	cin>>sy>>sx>>gy>>gx;
	sx--;sy--;gx--;gy--;
	
	vector<string> S(H);
	rep(i,H){
		cin>>S[i];
	}
	
	rep(i,H){
		rep(j,W){
			rep(k,6){
				dis[i][j][k] = Inf;
			}
		}
	}
	
	dis[sy][sx][0] = 0;
	queue<array<int,3>> Q;
	Q.push({sy,sx,0});
	vector<int> dy = {0,-1,0,1},dx = {1,0,-1,0};
	while(Q.size()>0){
		int y = Q.front()[0];
		int x = Q.front()[1];
		int d = Q.front()[2];
		Q.pop();
		rep(i,4){
			int yy = y + dy[i],xx = x+dx[i];
			if(yy<0||yy>=H||xx<0||xx>=W)continue;
			if(S[yy][xx]=='#')continue;
			vector<int> t(6,1);
			t[d] = 0;
			dice D;
			D.set(t);
			if(i==0)D.rotateFront(1);
			if(i==1)D.rotateLeft(1);
			if(i==2)D.rotateFront(3);
			if(i==3)D.rotateLeft(3);
			int dd;
			rep(j,6){
				if(D.number[j]==0){
					dd = j;
					break;
				}
			}
			if(dis[yy][xx][dd]!=Inf)continue;
			dis[yy][xx][dd] = dis[y][x][d] + 1;
			Q.push({yy,xx,dd});
		}
	}
	
	int ans = dis[gy][gx][0];
	if(ans==Inf)ans = -1;
	
	cout<<ans<<endl;
	
	
    return 0;
}
0