結果

問題 No.340 雪の足跡
ユーザー cielciel
提出日時 2016-06-27 21:06:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,059 bytes
コンパイル時間 719 ms
コンパイル使用メモリ 70,912 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2024-04-20 03:30:38
合計ジャッジ時間 6,711 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 RE -
testcase_07 RE -
testcase_08 WA -
testcase_09 RE -
testcase_10 WA -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <map>
#include <queue>
#include <cstdio>
using namespace std;
typedef pair<int,int> coor;
typedef struct{
	int x;
	int y;
}dir;
const dir D[]={
	{0,-1},{0,1},{-1,0},{1,0}
};

int main(){
	int W,H,N;
	scanf("%d%d%d",&W,&H,&N);
	vector<vector<int> >M(H*2-1);
	for(auto &e:M)e.resize(W*2-1);
	for(;N--;){
		int n,x,y;
		scanf("%d%d",&n,&x);
		for(int i=0;i<n;i++,x=y){
			scanf("%d",&y);
			int coorx=x%H*2,coory=x/H*2;
			if(y-x==1)M[coory][coorx+1]=1;
			if(y-x==-1)M[coory][coorx-1]=1;
			if(y-x==W)M[coory+1][coorx]=1;
			if(y-x==-W)M[coory-1][coorx]=1;
		}
	}
	map<coor,int> m={{{0,0},0}};
	queue<coor> q;
	for(q.push({0,0});!q.empty();){
		coor cur=q.front();q.pop();
		for(auto &d:D){
			if(0<=cur.first+d.x&&cur.first+d.x<W*2-1 && 0<=cur.second+d.y&&cur.second+d.y<H*2-1 && M[cur.second+d.y][cur.first+d.x]){
				coor nxt={cur.first+d.x*2,cur.second+d.y*2};
				if(m.find(nxt)==m.end()){
					q.push(nxt);
					m[nxt]=m[cur]+1;
					if(nxt==make_pair(W*2-2,H*2-2)){printf("%d\n",m[nxt]);return 0;}
				}
			}
		}
	}
	puts("Odekakedekinai...");
}
0