結果

問題 No.340 雪の足跡
ユーザー 184184
提出日時 2016-01-30 09:20:04
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,001 bytes
コンパイル時間 1,512 ms
コンパイル使用メモリ 51,504 KB
実行使用メモリ 814,356 KB
最終ジャッジ日時 2023-10-21 17:49:27
合計ジャッジ時間 7,352 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 RE -
testcase_08 AC 2 ms
4,348 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,348 KB
testcase_11 RE -
testcase_12 AC 4 ms
4,348 KB
testcase_13 RE -
testcase_14 AC 246 ms
40,892 KB
testcase_15 RE -
testcase_16 AC 129 ms
32,944 KB
testcase_17 AC 717 ms
105,016 KB
testcase_18 AC 544 ms
83,632 KB
testcase_19 AC 709 ms
104,488 KB
testcase_20 MLE -
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:9:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         int w,h,n;scanf("%d%d%d",&w,&h,&n);
      |                   ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:12:44: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |                 int m,sx,sy,x,y,a,b,d;scanf("%d%d",&m,&a);
      |                                       ~~~~~^~~~~~~~~~~~~~
main.cpp:15:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |                         scanf("%d",&b);x=b%w;y=b/h;
      |                         ~~~~~^~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <queue>
#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);
	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/h;
		for(int j=0;j<m;j++){
			scanf("%d",&b);x=b%w;y=b/h;
			if(sx==x){
				if(sy<y)d=w;else d=-w; 
				for(;a!=b;a+=d){
					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){
					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;
	vector<int> visit(w*h);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