結果

問題 No.340 雪の足跡
ユーザー tailstails
提出日時 2016-01-29 23:13:07
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 814 bytes
コンパイル時間 1,342 ms
コンパイル使用メモリ 164,236 KB
実行使用メモリ 11,356 KB
最終ジャッジ日時 2023-10-21 17:23:16
合計ジャッジ時間 4,643 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,696 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
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;

int w,h,n;
priority_queue<int> q;
int p[1000000];

void add(int a,int b){
	int c=a%w==b%w?2:1;
	int d=a%w==b%w?w:1;
	for(int e=min(a,b);e<a||e<b;e+=d){
		p[e]|=c;
	}
}

void enq(int x,int y,int z){
	q.push(x|y<<10|-z<<20);
}

int main(){
	cin>>w>>h>>n;
	for(int i=0;i<n;++i){
		int m,a,b;
		cin>>m>>a;
		for(int j=0;j<m;++j){
			cin>>b;
			add(a,b);
			a=b;
		}
	}
	enq(0,0,w+h-2);
	while(!q.empty()){
		int a=q.top();
		q.pop();
		int x=a&0x3ff;
		int y=a>>10&0x3ff;
		int z=-(a>>20);
		if(x==w-1&&y==h-1){
			cout<<z;
			exit(0);
		}
		if(y>0 && p[x+(y-1)*w]&2){
			enq(x,y-1,z+2);
		}
		if(y<h-1 && p[x+y*w]&2){
			enq(x,y+1,z);
		}
		if(x>0 && p[(x-1)+y*w]&1){
			enq(x-1,y,z+2);
		}
		if(x<w-1 && p[x+y*w]&1){
			enq(x+1,y,z);
		}
	}
	cout<<"Odekakedekinai..";
}
0