結果

問題 No.340 雪の足跡
ユーザー ciel
提出日時 2016-06-27 21:06:06
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,059 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 71,040 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-10-11 22:24:52
合計ジャッジ時間 7,236 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 4
other WA * 17 RE * 15
権限があれば一括ダウンロードができます

ソースコード

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