結果
| 問題 |
No.340 雪の足跡
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-16 20:33:43 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,936 bytes |
| コンパイル時間 | 1,652 ms |
| コンパイル使用メモリ | 180,708 KB |
| 実行使用メモリ | 55,552 KB |
| 最終ジャッジ日時 | 2024-10-15 13:54:39 |
| 合計ジャッジ時間 | 10,578 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 30 TLE * 2 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007
template<typename T1,typename T2>
ostream& operator <<(ostream &o,const pair<T1,T2> p){o<<"("<<p.first<<":"<<p.second<<")";return o;}
#define qmax 100000
int _qu[qmax][3];
int _quf=0,_qub=0;
inline void _push(int &a,int &b,int &c){
_qu[_quf][0]=a;
_qu[_quf][1]=b;
_qu[_quf][2]=c;
_quf=(++_quf)>=qmax ? 0 : _quf;
}
inline void _push(int a,int b,int c){
_qu[_quf][0]=a;
_qu[_quf][1]=b;
_qu[_quf][2]=c;
_quf=(++_quf)>=qmax ? 0 : _quf;
}
inline void _pop(int &a,int &b,int &c){
a=_qu[_qub][0];
b=_qu[_qub][1];
c=_qu[_qub][2];
_qub=(++_qub)>=qmax ? 0 : _qub;
}
int w,h;
int dp[1001][1001];
int vroad[1001][1001];
int hroad[1001][1001];
int vimos[1001][1001];
int himos[1001][1001];
map<pair<int,int>,int> hmap; // y,x !!
map<pair<int,int>,int> vmap;
int main(){
int i,j,k,l;
int x,y,d;
int m,n;
int u1,u2;
cin >>w>>h>>n;
pair<int,int> pii;
for (i=0;i<n;i++){
scanf("%d%d",&m,&u1);
for (j=1;j<=m;j++){
scanf("%d",&u2);
if (u1-w>=u2){ // down(flip->up)
//vimos[u2%w][u2/w]=max(u1/w-u2/w,vimos[u2%w][u2/w]);
pii.first=u2%w;pii.second=u2/w;
vmap[pii]=max(u1/w-u2/w,vmap[pii]);
}else if (u1>u2){ // left
//himos[u2%w][u2/w]=max(u1-u2,himos[u2%w][u2/w]);
pii.first=u2/w;pii.second=u2%w;
hmap[pii]=max(u1-u2,hmap[pii]);
}else if(u1+w>u2){ // right
//himos[u1%w][u1/w]=max(u2-u1,himos[u1%w][u1/w]);
pii.first=u1/w;pii.second=u1%w;
hmap[pii]=max(u2-u1,hmap[pii]);
}else{ // up(flip->down)
//vimos[u1%w][u1/w]=max(u2/w-u1/w,vimos[u1%w][u1/w]);
pii.first=u1%w;pii.second=u1/w;
vmap[pii]=max(u2/w-u1/w,vmap[pii]);
}
u1=u2;
}
}
for (auto p:vmap){
for (i=p.second-1;0<=i;i--){
vroad[p.first.first][p.first.second+i]=1;
}
}
for (auto p:hmap){
for (i=p.second-1;0<=i;i--){
hroad[p.first.second+i][p.first.first]=1;
}
}
//for (x=0;x<w;x++){
// i=0;
// for (y=0;y<h;y++){
// if (i--<vimos[x][y] && vimos[x][y]) i=vimos[x][y]-1;
// vroad[x][y]=(0<=i);
// }
//}
//for (y=0;y<h;y++){
// i=0;
// for (x=0;x<w;x++){
// if (i--<himos[x][y] && himos[x][y]) i=himos[x][y]-1;
// hroad[x][y]=(0<=i);
// }
//}
//for (y=0;y<h;y++){
// for (x=0;x<w;x++){
// printf("%d%d ",vroad[x][y],hroad[x][y]);
// }
// cout<<endl;
//}
queue<vector<int>> q;
_push(0,0,0);
dp[0][0]=1;
while (_qub!=_quf){
_pop(x,y,d);
if (x==w-1 && y==h-1){
cout<<d<<endl;
return 0;
}
//printf("%d %d %d\n",x,y,d);
if (x!=0 && hroad[x-1][y] && !dp[x-1][y]){dp[x-1][y]=1;_push(x-1,y,d+1);}
if ( hroad[x ][y] && !dp[x+1][y]){dp[x+1][y]=1;_push(x+1,y,d+1);}
if (y!=0 && vroad[x][y-1] && !dp[x][y-1]){dp[x][y-1]=1;_push(x,y-1,d+1);}
if ( vroad[x][y ] && !dp[x][y+1]){dp[x][y+1]=1;_push(x,y+1,d+1);}
}
cout<<"Odekakedekinai.."<<endl;
return 0;
}