結果

問題 No.340 雪の足跡
ユーザー cielciel
提出日時 2016-06-27 21:59:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 301 ms / 1,000 ms
コード長 1,162 bytes
コンパイル時間 530 ms
コンパイル使用メモリ 58,724 KB
実行使用メモリ 18,744 KB
最終ジャッジ日時 2023-08-25 02:46:22
合計ジャッジ時間 7,884 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 11 ms
4,376 KB
testcase_15 AC 13 ms
4,380 KB
testcase_16 AC 9 ms
4,380 KB
testcase_17 AC 18 ms
4,392 KB
testcase_18 AC 14 ms
4,404 KB
testcase_19 AC 16 ms
4,400 KB
testcase_20 AC 141 ms
18,724 KB
testcase_21 AC 86 ms
4,384 KB
testcase_22 AC 19 ms
18,660 KB
testcase_23 AC 150 ms
18,720 KB
testcase_24 AC 126 ms
18,732 KB
testcase_25 AC 134 ms
18,680 KB
testcase_26 AC 22 ms
4,376 KB
testcase_27 AC 6 ms
4,380 KB
testcase_28 AC 20 ms
4,380 KB
testcase_29 AC 231 ms
12,192 KB
testcase_30 AC 160 ms
9,948 KB
testcase_31 AC 254 ms
17,352 KB
testcase_32 AC 301 ms
18,744 KB
testcase_33 AC 237 ms
18,688 KB
testcase_34 AC 298 ms
18,720 KB
testcase_35 AC 166 ms
18,728 KB
testcase_36 AC 165 ms
18,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <queue>
#include <cstdio>
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);
	std::vector<std::vector<int>>M(H*2+1);
	for(auto&e:M)e.resize(W*2+1);
	for(int n,x,y;N--;){
		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,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{
				if(k/=W,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;
	std::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