結果

問題 No.340 雪の足跡
ユーザー 184184
提出日時 2016-01-30 09:56:55
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,167 bytes
コンパイル時間 1,704 ms
コンパイル使用メモリ 70,448 KB
実行使用メモリ 29,240 KB
最終ジャッジ日時 2023-10-21 17:50:04
合計ジャッジ時間 6,264 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 6 ms
4,364 KB
testcase_14 AC 224 ms
24,556 KB
testcase_15 AC 295 ms
25,612 KB
testcase_16 AC 115 ms
13,204 KB
testcase_17 AC 458 ms
29,240 KB
testcase_18 AC 372 ms
29,240 KB
testcase_19 AC 463 ms
29,240 KB
testcase_20 TLE -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         int w,h,n;scanf("%d%d%d",&w,&h,&n);
      |                   ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:15:44: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |                 int m,sx,sy,x,y,a,b,d;scanf("%d%d",&m,&a);
      |                                       ~~~~~^~~~~~~~~~~~~~
main.cpp:18:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |                         scanf("%d",&b);x=b%w;y=b/w;
      |                         ~~~~~^~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <queue>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;
 
int main(){
	int w,h,n;scanf("%d%d%d",&w,&h,&n);
	vector< vector<int> > v(h*w);
	vector<int> visit(w*h);
	vector< map<int,int> > mp(h*w);
	for(int i=0;i<n;i++){
		int m,sx,sy,x,y,a,b,d;scanf("%d%d",&m,&a);
		sx=a%w;sy=a/w;
		for(int j=0;j<m;j++){
			scanf("%d",&b);x=b%w;y=b/w;
			if(sx==x){
				if(sy<y)d=w;else d=-w; 
				for(;a!=b;a+=d){
					if(mp[a][a+d])continue;
					mp[a][a+d]=mp[a+d][a]=1;
					v[a].push_back(a+d);
					v[a+d].push_back(a);
				}
			}
			else if(sy==y){
				if(sx<x)d=1;else d=-1;
				for(;a!=b;a+=d){
					if(mp[a][a+d])continue;
					mp[a][a+d]=mp[a+d][a]=1;
					v[a].push_back(a+d);
					v[a+d].push_back(a);
				}
			}
			a=b;sx=x;sy=y;
		}
	}
	
	queue<int> q;
	q.push(0);
	int g=h*w-1;visit[0]=1;
	int a,cnt=0,num=1,ncnt=0;
	while(q.size()){
		a=q.front();q.pop();
		if(a==g){a=-1;break;}
		num--;
		for(int i=0;i<v[a].size();i++){
			if(visit[v[a][i]]==0){ncnt++;visit[v[a][i]]=1;q.push(v[a][i]);}
		}
		if(num==0){cnt++;num=ncnt;ncnt=0;}
	}
	if(a>=0)printf("Odekakedekinai..\n");
	else printf("%d\n",cnt);
	return 0;
}
0