結果
| 問題 |
No.340 雪の足跡
|
| コンテスト | |
| ユーザー |
184
|
| 提出日時 | 2016-01-30 10:12:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,158 bytes |
| コンパイル時間 | 1,210 ms |
| コンパイル使用メモリ | 58,836 KB |
| 実行使用メモリ | 33,856 KB |
| 最終ジャッジ日時 | 2024-09-21 19:04:38 |
| 合計ジャッジ時間 | 5,659 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 6 RE * 10 TLE * 1 -- * 15 |
コンパイルメッセージ
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;
| ~~~~~^~~~~~~~~
ソースコード
#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);
int mp[1001][1001]={};
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;
}
184