結果

問題 No.340 雪の足跡
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-06-01 01:48:13
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,577 bytes
コンパイル時間 1,551 ms
コンパイル使用メモリ 161,972 KB
実行使用メモリ 23,332 KB
最終ジャッジ日時 2023-08-12 16:55:13
合計ジャッジ時間 9,789 ms
ジャッジサーバーID
(参考情報)
judge11 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 19 ms
4,908 KB
testcase_15 AC 24 ms
4,932 KB
testcase_16 AC 18 ms
4,380 KB
testcase_17 AC 32 ms
5,288 KB
testcase_18 AC 24 ms
5,452 KB
testcase_19 AC 33 ms
5,224 KB
testcase_20 AC 305 ms
22,688 KB
testcase_21 AC 178 ms
4,384 KB
testcase_22 AC 20 ms
22,536 KB
testcase_23 WA -
testcase_24 AC 283 ms
22,720 KB
testcase_25 AC 326 ms
23,040 KB
testcase_26 AC 48 ms
4,380 KB
testcase_27 AC 10 ms
4,380 KB
testcase_28 AC 43 ms
4,424 KB
testcase_29 AC 370 ms
14,920 KB
testcase_30 AC 254 ms
12,164 KB
testcase_31 AC 384 ms
21,420 KB
testcase_32 AC 452 ms
23,180 KB
testcase_33 AC 352 ms
23,332 KB
testcase_34 AC 452 ms
23,108 KB
testcase_35 AC 330 ms
23,032 KB
testcase_36 AC 331 ms
23,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.06.01 01:48:08
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int w, h;
vector< vector< ll > > g1, g2;
void f(int x, int y) {
    if (x > y) swap(x, y);
    if (x % w == y % w) {
        g1[x / w][x % w]++;
        g1[y / w + 1][y % w]--;
    } else {
        g2[x / w][x % w]++;
        g2[y / w][y % w + 1]--;
    }
}
int main() {
    int n;
    cin >> w >> h >> n;
    g1.resize(h + 1, vector< ll >(w + 1,0));//縦
    g2.resize(h + 1, vector< ll >(w + 1,0));//横
    for (int i = 0; i < n; i++) {
        int m;
        cin >> m;
        int pre = -1;
        for (int i = 0; i < m + 1; i++) {
            int b;
            cin >> b;
            if (pre != -1) {
                f(pre,b);
            }
            pre = b;
        }
    }
    for (int i = 0; i < w; i++) {
        for (int j = 0; j < h; j++) {
            g1[j+1][i] += g1[j][i];
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            g2[i][j+1] += g2[i][j];
        }
    }
    vector<vector<int>> dist(h,vector<int>(w,-1));
    dist[0][0] = 0;
    queue<pair<int,int>> que;
    que.push({0,0});
    while(!que.empty()) {
        auto p = que.front(); que.pop();
        int nx = p.first;
        int ny = p.second;
        {
            int x = nx + 1;
            int y = ny;
            if (x >= 0 && x < h && y >= 0 && y < w && g1[nx][ny] > 0 && g1[x][y] > 0 && dist[x][y] == -1) {
                dist[x][y] = dist[nx][ny] + 1;
                que.push({x,y});
            }
        }
        {
            int x = nx - 1;
            int y = ny;
            if (x >= 0 && x < h && y >= 0 && y < w && g1[nx][ny] > 0 && g1[x][y] > 0 && dist[x][y] == -1) {
                dist[x][y] = dist[nx][ny] + 1;
                que.push({x,y});
            }
        }
        {
            int x = nx;
            int y = ny + 1;
            if (x >= 0 && x < h && y >= 0 && y < w && g2[nx][ny] > 0 && g2[x][y] > 0 && dist[x][y] == -1) {
                dist[x][y] = dist[nx][ny] + 1;
                que.push({x,y});
            }
        }
        {
            int x = nx;
            int y = ny - 1;
            if (x >= 0 && x < h && y >= 0 && y < w && g2[nx][ny] > 0 && g2[x][y] > 0 && dist[x][y] == -1) {
                dist[x][y] = dist[nx][ny] + 1;
                que.push({x,y});
            }
        }
    }
    if (dist[h-1][w-1] == -1) {
        puts("Odekakedekinai..");
    }
    else {
        cout << dist[h-1][w-1] << endl;
    }
    return 0;
}
0