結果

問題 No.340 雪の足跡
ユーザー maimai
提出日時 2016-07-16 20:36:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 190 ms / 1,000 ms
コード長 3,149 bytes
コンパイル時間 1,354 ms
コンパイル使用メモリ 165,956 KB
実行使用メモリ 24,408 KB
最終ジャッジ日時 2024-04-23 13:52:50
合計ジャッジ時間 4,823 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,892 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 4 ms
10,348 KB
testcase_14 AC 14 ms
13,024 KB
testcase_15 AC 15 ms
14,688 KB
testcase_16 AC 12 ms
8,064 KB
testcase_17 AC 17 ms
10,624 KB
testcase_18 AC 15 ms
10,624 KB
testcase_19 AC 19 ms
10,624 KB
testcase_20 AC 121 ms
17,016 KB
testcase_21 AC 94 ms
15,500 KB
testcase_22 AC 9 ms
11,392 KB
testcase_23 AC 131 ms
16,768 KB
testcase_24 AC 121 ms
16,096 KB
testcase_25 AC 132 ms
16,000 KB
testcase_26 AC 23 ms
12,360 KB
testcase_27 AC 7 ms
5,376 KB
testcase_28 AC 21 ms
10,904 KB
testcase_29 AC 139 ms
16,896 KB
testcase_30 AC 105 ms
23,052 KB
testcase_31 AC 176 ms
24,344 KB
testcase_32 AC 186 ms
24,408 KB
testcase_33 AC 157 ms
24,296 KB
testcase_34 AC 190 ms
24,404 KB
testcase_35 AC 135 ms
22,372 KB
testcase_36 AC 139 ms
22,484 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];

int main(){
    int i,j,k,l;
    int x,y,d;
    int m,n;
    int u1,u2;
    cin >>w>>h>>n;
    
    for (i=0;i<n;i++){
        scanf("%d",&m);
        scanf("%d",&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]);
            }else if (u1>u2){ // left
                himos[u2%w][u2/w]=max(u1-u2,himos[u2%w][u2/w]);
            }else if(u1+w>u2){ // right
                himos[u1%w][u1/w]=max(u2-u1,himos[u1%w][u1/w]);
            }else{ // up(flip->down)
                vimos[u1%w][u1/w]=max(u2/w-u1/w,vimos[u1%w][u1/w]);
            }
            u1=u2;
        }
    }
    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;
    //}
    
    
    _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