結果
問題 |
No.340 雪の足跡
|
ユーザー |
![]() |
提出日時 | 2016-01-30 09:09:49 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,001 bytes |
コンパイル時間 | 425 ms |
コンパイル使用メモリ | 51,556 KB |
実行使用メモリ | 822,784 KB |
最終ジャッジ日時 | 2024-09-21 19:03:38 |
合計ジャッジ時間 | 6,828 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 5 WA * 1 RE * 9 MLE * 1 -- * 16 |
コンパイルメッセージ
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; | ~~~~~^~~~~~~~~
ソースコード
#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=h;else d=-h; 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; }