結果

問題 No.340 雪の足跡
ユーザー maimai
提出日時 2016-06-13 18:54:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,019 bytes
コンパイル時間 1,599 ms
コンパイル使用メモリ 172,928 KB
実行使用メモリ 23,552 KB
最終ジャッジ日時 2024-04-17 19:07:10
合計ジャッジ時間 6,648 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
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 WA -
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 22 ms
9,600 KB
testcase_15 AC 25 ms
8,960 KB
testcase_16 AC 17 ms
7,680 KB
testcase_17 AC 30 ms
9,728 KB
testcase_18 AC 27 ms
9,600 KB
testcase_19 AC 30 ms
9,728 KB
testcase_20 AC 138 ms
15,768 KB
testcase_21 AC 95 ms
15,472 KB
testcase_22 AC 10 ms
11,392 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 185 ms
16,896 KB
testcase_26 AC 26 ms
5,376 KB
testcase_27 AC 7 ms
5,376 KB
testcase_28 AC 29 ms
7,424 KB
testcase_29 AC 235 ms
15,872 KB
testcase_30 AC 190 ms
20,096 KB
testcase_31 AC 321 ms
23,296 KB
testcase_32 AC 374 ms
23,432 KB
testcase_33 AC 318 ms
23,504 KB
testcase_34 AC 349 ms
23,552 KB
testcase_35 AC 279 ms
21,564 KB
testcase_36 AC 272 ms
21,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long int ll;

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;
    cin >>w>>h>>n;
    
    for (i=0;i<n;i++){
        int u1,u2;
        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];
            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];
            hroad[x][y]=(0<=i);
        }
    }
    
    queue<vector<int>> q;
    q.push(vector<int>{0,0,0});
    while (!q.empty()){
        vector<int> &e=q.front();
        x=e[0];y=e[1];d=e[2];q.pop();
        //printf("%d %d %d\n",x,y,d);
        if (dp[x][y]) continue;
        if (x==w-1 && y==h-1){
            cout<<d<<endl;
            return 0;
        }
        dp[x][y]=1;
        if (x!=0 && hroad[x-1][y]){q.push(vector<int>{x-1,y,d+1});}
        if (        hroad[x  ][y]){q.push(vector<int>{x+1,y,d+1});}
        if (y!=0 && vroad[x][y-1]){q.push(vector<int>{x,y-1,d+1});}
        if (        vroad[x][y  ]){q.push(vector<int>{x,y+1,d+1});}
    }
    cout<<"Odekakedekinai.."<<endl;
    return 0;
    
}
0