結果

問題 No.340 雪の足跡
ユーザー furafura
提出日時 2020-01-31 18:13:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 401 ms / 1,000 ms
コード長 1,260 bytes
コンパイル時間 1,834 ms
コンパイル使用メモリ 176,368 KB
実行使用メモリ 69,688 KB
最終ジャッジ日時 2023-10-17 08:25:13
合計ジャッジ時間 10,713 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,860 KB
testcase_01 AC 2 ms
5,864 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
5,860 KB
testcase_04 AC 3 ms
5,796 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
5,860 KB
testcase_07 AC 2 ms
5,788 KB
testcase_08 AC 3 ms
5,804 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
5,808 KB
testcase_11 AC 3 ms
6,064 KB
testcase_12 AC 3 ms
6,148 KB
testcase_13 AC 4 ms
6,360 KB
testcase_14 AC 25 ms
14,468 KB
testcase_15 AC 27 ms
14,732 KB
testcase_16 AC 17 ms
10,312 KB
testcase_17 AC 33 ms
15,524 KB
testcase_18 AC 30 ms
15,524 KB
testcase_19 AC 32 ms
15,524 KB
testcase_20 AC 183 ms
44,472 KB
testcase_21 AC 97 ms
4,348 KB
testcase_22 AC 26 ms
38,328 KB
testcase_23 AC 249 ms
69,688 KB
testcase_24 AC 138 ms
38,792 KB
testcase_25 AC 190 ms
52,260 KB
testcase_26 AC 27 ms
11,012 KB
testcase_27 AC 7 ms
5,880 KB
testcase_28 AC 30 ms
12,884 KB
testcase_29 AC 254 ms
44,952 KB
testcase_30 AC 180 ms
36,108 KB
testcase_31 AC 354 ms
64,476 KB
testcase_32 AC 401 ms
69,688 KB
testcase_33 AC 365 ms
69,688 KB
testcase_34 AC 401 ms
69,688 KB
testcase_35 AC 371 ms
69,688 KB
testcase_36 AC 376 ms
69,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using graph=vector<vector<int>>;

vector<int> distance(const graph& G,int s){
	const int INF=INT_MAX;
	int n=G.size();
	vector<int> d(n,INF);
	d[s]=0;
	queue<int> Q; Q.emplace(s);
	while(!Q.empty()){
		int u=Q.front(); Q.pop();
		for(int v:G[u]) if(d[v]==INF) {
			d[v]=d[u]+1;
			Q.emplace(v);
		}
	}
	return d;
}

int main(){
	int h,w,n; scanf("%d%d%d",&w,&h,&n);

	static int rsum[1000][1000],csum[1000][1000];
	rep(i,n){
		int m; scanf("%d",&m);
		static int b[1001];
		rep(j,m+1) scanf("%d",&b[j]);

		rep(j,m){
			int y1=b[ j ]/w,x1=b[ j ]%w;
			int y2=b[j+1]/w,x2=b[j+1]%w;
			if(y1==y2){
				csum[y1][min(x1,x2)]++;
				csum[y1][max(x1,x2)]--;
			}
			else{
				rsum[min(y1,y2)][x1]++;
				rsum[max(y1,y2)][x1]--;
			}
		}
	}

	rep(i,h) rep(j,w-1) csum[i][j+1]+=csum[i][j];
	rep(j,w) rep(i,h-1) rsum[i+1][j]+=rsum[i][j];

	graph G(h*w);
	rep(i,h) rep(j,w) {
		if(rsum[i][j]>0){
			G[i*w+j].emplace_back((i+1)*w+j);
			G[(i+1)*w+j].emplace_back(i*w+j);
		}
		if(csum[i][j]>0){
			G[i*w+j].emplace_back(i*w+j+1);
			G[i*w+j+1].emplace_back(i*w+j);
		}
	}

	int ans=distance(G,0)[h*w-1];
	if(ans<h*w) printf("%d\n",ans);
	else puts("Odekakedekinai..");

	return 0;
}
0