結果
問題 |
No.340 雪の足跡
|
ユーザー |
![]() |
提出日時 | 2016-01-31 10:26:44 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,957 bytes |
コンパイル時間 | 1,651 ms |
コンパイル使用メモリ | 172,188 KB |
実行使用メモリ | 84,096 KB |
最終ジャッジ日時 | 2024-09-21 19:37:44 |
合計ジャッジ時間 | 10,876 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 13 TLE * 3 -- * 16 |
ソースコード
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> veci; typedef vector<string> vecs; template<class T,class U> using Hash=unordered_map<T,U>; #define REP(i, a, n) for(ll i = a; i < n; i++) #define rep(i, n) REP(i, 0, n) template<class T> T read(){T a;cin >> a;return a;} template<class T> T read(T& a){cin >> a;} template<class T> void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}} template<class T> void write(T a){cout << a << endl;} void write(double a){cout << fixed << setprecision(12) << a << endl;} template<class T> void warr(T a, int n, char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;} ll gcd(ll a, ll b){while(true){ll k = a % b;if(k == 0)return b;a = b;b = k;}} int main(void) { int w,h,n; Hash<int,bool>* a=new Hash<int,bool>[1000*1000]; cin>>w>>h>>n; rep(i,n) { int m=read<int>(); int bf=read<int>(); rep(j,m){ int b=read<int>(); int sign=(b<bf)?1:-1; int sb=b; if(b%w==bf%w) while(sb!=bf){ a[sb][sb+w*sign]=a[sb+w*sign][sb]=true; sb+=w*sign; } else while(sb!=bf){ a[sb][sb+sign]=a[sb+sign][sb]=true; sb+=sign; } bf=b; } } bool vis[1000*1000]={0}; queue<int> q; int res[1000*1000]={0}; int WH=w*h-1; q.push(0); vis[0]=true; while(!q.empty()){ int cur=q.front(); q.pop(); for(auto p : a[cur]){ if(!vis[p.first]){ vis[p.first]=true; res[p.first]=res[cur]+1; q.push(p.first); } } if(vis[WH]) break; } if(vis[WH]) write(res[WH]); else write("Odekakedekinai.."); return 0; }