結果

問題 No.340 雪の足跡
ユーザー fiordfiord
提出日時 2016-01-31 10:29:50
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,640 bytes
コンパイル時間 1,995 ms
コンパイル使用メモリ 175,880 KB
実行使用メモリ 32,128 KB
最終ジャッジ日時 2023-10-21 18:17:36
合計ジャッジ時間 6,202 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
12,120 KB
testcase_01 AC 2 ms
7,780 KB
testcase_02 AC 2 ms
5,740 KB
testcase_03 AC 2 ms
7,776 KB
testcase_04 AC 3 ms
7,780 KB
testcase_05 AC 2 ms
5,716 KB
testcase_06 AC 2 ms
7,776 KB
testcase_07 AC 2 ms
5,748 KB
testcase_08 AC 3 ms
7,788 KB
testcase_09 AC 2 ms
7,764 KB
testcase_10 AC 3 ms
7,792 KB
testcase_11 AC 4 ms
7,932 KB
testcase_12 AC 4 ms
7,928 KB
testcase_13 AC 5 ms
8,064 KB
testcase_14 AC 29 ms
14,252 KB
testcase_15 AC 34 ms
14,264 KB
testcase_16 AC 24 ms
14,252 KB
testcase_17 AC 43 ms
14,264 KB
testcase_18 AC 36 ms
14,264 KB
testcase_19 AC 43 ms
14,264 KB
testcase_20 AC 337 ms
28,076 KB
testcase_21 AC 204 ms
7,792 KB
testcase_22 AC 13 ms
27,864 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fst first
#define sec second
ll dist[1024][1024];
ll lr[1024][1024],ud[1024][1024];
int main(){
	ll w,h,n;	cin>>w>>h>>n;
	for(ll i=0;i<n;i++){
		ll m;	cin>>m;
		vector<pair<ll,ll>> b;
		for(ll j=0;j<m+1;j++){
			ll num;	cin>>num;
			b.push_back(make_pair(num/w,num%w));//y,x
		}
		for(ll j=1;j<=m;j++){
			if(b[j].fst==b[j-1].fst){//横方向の移動
				ll sml=min(b[j].sec,b[j-1].sec);
				ll big=max(b[j].sec,b[j-1].sec);
				lr[b[j].fst][sml]++;	lr[b[j].fst][big]--;
			}
			else{
				ll sml=min(b[j].fst,b[j-1].fst);
				ll big=max(b[j].fst,b[j-1].fst);
				ud[sml][b[j].sec]++;	ud[big][b[j].sec]--;
			}
		}
	}
	for(ll i=0;i<h;i++){
		for(ll j=1;j<w;j++)	lr[i][j]+=lr[i][j-1];
	}
	for(ll i=1;i<h;i++){
		for(ll j=0;j<w;j++)	ud[i][j]+=ud[i-1][j];
	}
	for(ll i=0;i<h;i++)	for(ll j=0;j<w;j++)	dist[i][j]=LLONG_MAX;
	dist[0][0]=0;
	priority_queue<tuple<ll,ll,ll>> pq;
	pq.push(make_tuple(-0,0,0));
	while(!pq.empty()){
		auto it=pq.top();	pq.pop();
		ll cost=-get<0>(it);
		ll 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