結果

問題 No.340 雪の足跡
ユーザー tailstails
提出日時 2016-01-29 23:16:56
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 868 bytes
コンパイル時間 1,386 ms
コンパイル使用メモリ 163,784 KB
実行使用メモリ 8,580 KB
最終ジャッジ日時 2023-10-21 17:24:42
合計ジャッジ時間 14,397 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,716 KB
testcase_01 AC 2 ms
5,716 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
5,716 KB
testcase_04 AC 2 ms
5,720 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
5,716 KB
testcase_07 AC 2 ms
5,720 KB
testcase_08 AC 2 ms
5,720 KB
testcase_09 AC 2 ms
5,716 KB
testcase_10 AC 2 ms
5,720 KB
testcase_11 AC 4 ms
5,720 KB
testcase_12 AC 3 ms
5,720 KB
testcase_13 AC 3 ms
5,724 KB
testcase_14 AC 20 ms
5,792 KB
testcase_15 AC 27 ms
5,796 KB
testcase_16 AC 20 ms
5,752 KB
testcase_17 AC 35 ms
5,812 KB
testcase_18 AC 28 ms
5,812 KB
testcase_19 AC 35 ms
5,812 KB
testcase_20 TLE -
testcase_21 AC 949 ms
5,716 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 WA -
testcase_24 TLE -
testcase_25 AC 735 ms
8,492 KB
testcase_26 AC 57 ms
5,728 KB
testcase_27 AC 11 ms
5,720 KB
testcase_28 AC 50 ms
5,764 KB
testcase_29 AC 547 ms
8,344 KB
testcase_30 AC 327 ms
6,160 KB
testcase_31 AC 585 ms
8,444 KB
testcase_32 AC 715 ms
8,556 KB
testcase_33 AC 531 ms
8,556 KB
testcase_34 AC 710 ms
8,556 KB
testcase_35 TLE -
testcase_36 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int w,h,n;
priority_queue<int> q;
int p[1000000];
bool v[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){
	if(!v[x+y*w]){
		v[x+y*w]=true;
		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