結果

問題 No.340 雪の足跡
ユーザー cielciel
提出日時 2016-06-27 21:56:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 219 ms / 1,000 ms
コード長 1,209 bytes
コンパイル時間 626 ms
コンパイル使用メモリ 59,520 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2024-04-20 03:33:03
合計ジャッジ時間 4,472 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 10 ms
5,376 KB
testcase_15 AC 11 ms
5,376 KB
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 15 ms
5,376 KB
testcase_18 AC 12 ms
5,376 KB
testcase_19 AC 14 ms
5,376 KB
testcase_20 AC 126 ms
19,328 KB
testcase_21 AC 83 ms
5,376 KB
testcase_22 AC 18 ms
19,456 KB
testcase_23 AC 135 ms
19,584 KB
testcase_24 AC 115 ms
19,456 KB
testcase_25 AC 124 ms
19,456 KB
testcase_26 AC 20 ms
5,376 KB
testcase_27 AC 5 ms
5,376 KB
testcase_28 AC 18 ms
5,376 KB
testcase_29 AC 154 ms
12,800 KB
testcase_30 AC 99 ms
10,880 KB
testcase_31 AC 182 ms
18,048 KB
testcase_32 AC 219 ms
19,456 KB
testcase_33 AC 162 ms
19,456 KB
testcase_34 AC 208 ms
19,328 KB
testcase_35 AC 147 ms
19,456 KB
testcase_36 AC 146 ms
19,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <queue>
#include <cstdio>
using namespace std;
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 cx=x%W*2,cy=x/W*2;
			int k=y-x>0?y-x:x-y;
			if(k<W){
				if(y-x>0)M[cy][cx+1]++,M[cy][cx+k*2+1]--;
				else M[cy][cx-k*2+1]++,M[cy][cx+1]--;
			}else{
				k/=W;
				if(y-x>0)M[cy+1][cx]++,M[cy+k*2+1][cx]--;
				else M[cy-k*2+1][cx]++,M[cy+1][cx]--;
			}
		}
	}
	for(int i=1;i<W;i++)for(int j=0;j<H;j++)M[j*2][i*2+1]+=M[j*2][i*2-1];
	for(int i=0;i<W;i++)for(int j=1;j<H;j++)M[j*2+1][i*2]+=M[j*2-1][i*2];
	M[0][0]=1;
	queue<dir> q;
	for(q.push({0,0});!q.empty();){
		dir cur=q.front();q.pop();
		if(W*2+H*2-4-cur.x-cur.y==0)return !printf("%d\n",M[cur.y][cur.x]-1);
		for(auto &d:D){
			if(0<=cur.x+d.x&&cur.x+d.x<W*2-1 && 0<=cur.y+d.y&&cur.y+d.y<H*2-1 && M[cur.y+d.y][cur.x+d.x]){
				dir nxt={cur.x+d.x*2,cur.y+d.y*2};
				if(!M[nxt.y][nxt.x]){
					q.push(nxt);
					M[nxt.y][nxt.x]=M[cur.y][cur.x]+1;
				}
			}
		}
	}
	puts("Odekakedekinai..");
}
0