結果
問題 |
No.340 雪の足跡
|
ユーザー |
![]() |
提出日時 | 2016-01-29 22:34:22 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,358 bytes |
コンパイル時間 | 1,351 ms |
コンパイル使用メモリ | 169,228 KB |
実行使用メモリ | 67,712 KB |
最終ジャッジ日時 | 2024-09-21 18:19:16 |
合計ジャッジ時間 | 7,682 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 15 TLE * 1 -- * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int H,W,N; set<int> L[1000000]; int dist[1000001]; void solve() { int i,j,k,l,r,x,y; string s; cin>>W>>H>>N; FOR(i,N) { cin>>x; int pre=-1; FOR(j,x+1) { cin>>y; if(pre!=-1) { if(abs(y-pre)<W) { for(k=min(y,pre);k<max(y,pre);k++) L[k].insert(k+1),L[k+1].insert(k); } else { for(k=min(y,pre);k<max(y,pre);k+=W) L[k].insert(k+W),L[k+W].insert(k); } } pre=y; } } FOR(i,W*H) dist[i]=1<<30; dist[0]=0; queue<int> Q; Q.push(0); while(Q.size()) { int cur=Q.front(); Q.pop(); if(cur==W*H-1) return _P("%d\n",dist[cur]); FORR(r,L[cur]) { if(dist[r]>dist[cur]+1) { dist[r]=dist[cur]+1; Q.push(r); } } } _P("Odekakedekinai..\n"); } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); solve(); return 0; }