結果

問題 No.340 雪の足跡
ユーザー maimai
提出日時 2016-07-16 20:33:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,936 bytes
コンパイル時間 1,631 ms
コンパイル使用メモリ 176,916 KB
実行使用メモリ 57,256 KB
最終ジャッジ日時 2024-04-23 13:52:41
合計ジャッジ時間 10,126 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
10,060 KB
testcase_01 AC 3 ms
11,976 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
9,928 KB
testcase_04 AC 2 ms
9,804 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 3 ms
11,976 KB
testcase_07 AC 2 ms
7,884 KB
testcase_08 AC 3 ms
9,932 KB
testcase_09 AC 2 ms
8,016 KB
testcase_10 AC 3 ms
9,804 KB
testcase_11 AC 5 ms
10,172 KB
testcase_12 AC 4 ms
9,912 KB
testcase_13 AC 5 ms
12,164 KB
testcase_14 AC 34 ms
14,908 KB
testcase_15 AC 40 ms
13,660 KB
testcase_16 AC 31 ms
12,084 KB
testcase_17 AC 57 ms
16,412 KB
testcase_18 AC 42 ms
13,672 KB
testcase_19 AC 61 ms
16,548 KB
testcase_20 AC 124 ms
16,984 KB
testcase_21 AC 95 ms
14,028 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 165 ms
15,944 KB
testcase_24 AC 110 ms
14,020 KB
testcase_25 AC 128 ms
15,240 KB
testcase_26 AC 75 ms
11,448 KB
testcase_27 AC 12 ms
12,004 KB
testcase_28 AC 77 ms
14,156 KB
testcase_29 AC 868 ms
47,076 KB
testcase_30 AC 594 ms
39,168 KB
testcase_31 AC 961 ms
51,880 KB
testcase_32 TLE -
testcase_33 AC 816 ms
48,996 KB
testcase_34 TLE -
testcase_35 AC 151 ms
18,060 KB
testcase_36 AC 163 ms
17,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    
}
0