結果

問題 No.340 雪の足跡
ユーザー fiordfiord
提出日時 2016-01-31 10:18:08
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,655 bytes
コンパイル時間 1,558 ms
コンパイル使用メモリ 173,616 KB
実行使用メモリ 15,388 KB
最終ジャッジ日時 2023-10-21 18:17:12
合計ジャッジ時間 8,492 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define fst first
#define sec second
int dist[1000][1000];
int lr[1000][1000],ud[1000][1000];
int main(){
	int w,h,n;	cin>>w>>h>>n;
	for(int i=0;i<n;i++){
		int m;	cin>>m;
		vector<pair<int,int>> b;
		for(int j=0;j<m+1;j++){
			int num;	cin>>num;
			b.push_back(make_pair(num/w,num%w));//y,x
		}
		cout<<endl;
		for(int j=1;j<=m;j++){
			if(b[j].fst==b[j-1].fst){//横方向の移動
				int sml=min(b[j].sec,b[j-1].sec);
				int big=max(b[j].sec,b[j-1].sec);
				lr[b[j].fst][sml]++;	lr[b[j].fst][big]--;
			}
			else{
				int sml=min(b[j].fst,b[j-1].fst);
				int big=max(b[j].fst,b[j-1].fst);
				ud[sml][b[j].sec]++;	ud[big][b[j].sec]--;
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=1;j<w;j++)	lr[i][j]+=lr[i][j-1];
	}
	for(int i=1;i<h;i++){
		for(int j=0;j<w;j++)	ud[i][j]+=ud[i-1][j];
	}
	for(int i=0;i<h;i++)	for(int j=0;j<w;j++)	dist[i][j]=INT_MAX;
	dist[0][0]=0;
	priority_queue<tuple<int,int,int>> pq;
	pq.push(make_tuple(-0,0,0));
	while(!pq.empty()){
		auto it=pq.top();	pq.pop();
		int cost=-get<0>(it);
		int y=get<1>(it),x=get<2>(it);
		if(cost>dist[y][x])	continue;
		if(y==h-1&&x==w-1){
			cout<<cost<<endl;
			return 0;
		}
		cost++;
		if(lr[y][x]&&dist[y][x+1]>cost){
			dist[y][x+1]=cost;
			pq.push(make_tuple(-cost,y,x+1));
		}
		if(x>0&&lr[y][x-1]&&dist[y][x-1]>cost){
			dist[y][x+1]=cost;
			pq.push(make_tuple(-cost,y,x-1));
		}
		if(ud[y][x]&&dist[y+1][x]>cost){
			dist[y+1][x]=cost;
			pq.push(make_tuple(-cost,y+1,x));
		}
		if(y>0&&ud[y-1][x]&&dist[y-1][x]>cost){
			dist[y-1][x]=cost;
			pq.push(make_tuple(-cost,y-1,x));
		}
	}
	cout<<"Odekakedekinai.."<<endl;
	return 0;
}
0