結果

問題 No.340 雪の足跡
ユーザー ctyl_0ctyl_0
提出日時 2016-02-19 18:20:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 417 ms / 1,000 ms
コード長 1,958 bytes
コンパイル時間 1,000 ms
コンパイル使用メモリ 95,032 KB
実行使用メモリ 69,552 KB
最終ジャッジ日時 2023-10-23 18:32:37
合計ジャッジ時間 6,576 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 23 ms
8,132 KB
testcase_15 AC 25 ms
8,396 KB
testcase_16 AC 14 ms
5,492 KB
testcase_17 AC 30 ms
9,188 KB
testcase_18 AC 29 ms
9,188 KB
testcase_19 AC 30 ms
9,188 KB
testcase_20 AC 153 ms
44,472 KB
testcase_21 AC 67 ms
4,348 KB
testcase_22 AC 22 ms
38,400 KB
testcase_23 AC 227 ms
69,552 KB
testcase_24 AC 111 ms
38,664 KB
testcase_25 AC 167 ms
51,864 KB
testcase_26 AC 20 ms
4,348 KB
testcase_27 AC 5 ms
4,348 KB
testcase_28 AC 24 ms
6,284 KB
testcase_29 AC 253 ms
41,780 KB
testcase_30 AC 182 ms
32,676 KB
testcase_31 AC 362 ms
63,880 KB
testcase_32 AC 415 ms
69,552 KB
testcase_33 AC 378 ms
69,552 KB
testcase_34 AC 417 ms
69,552 KB
testcase_35 AC 352 ms
69,552 KB
testcase_36 AC 351 ms
69,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;

template <typename T>
inline void output(T a, int p) {
    if(p){
        cout << fixed << setprecision(p)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int W, H, N;
    cin >> W >> H >> N;
    vector<int> R(W * H, 0), U(W * H, 0), D(W * H, mod); // Right, Up の最大距離, dist
    vector<vector<int>> L(W * H); // 辺リスト
    rep(i, N){
        int M;
        cin >> M;
        int pre, now;
        cin >> pre;
        rep(i, M){
            cin >> now;
            if (abs(pre - now) < W) R[min(pre, now)] = max(R[min(pre, now)], abs(pre - now));
            else U[min(pre, now)] = max(U[min(pre, now)], abs(pre / W - now / W));
            pre = now;
        }
    }
    
    rep(y, H) rep(x, W){
        int c = x + y * W;
        if (x) R[c] = max(R[c], R[c - 1] - 1);
        if (y) U[c] = max(U[c], U[c - W] - 1);
        if (R[c]) L[c].pb(c + 1), L[c + 1].pb(c);
        if (U[c]) L[c].pb(c + W), L[c + W].pb(c);
    }
    
    D[0] = 0;
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        int t = q.front();
        q.pop();
        rep(i, L[t].size()){
            if (D[L[t][i]] > D[t] + 1) {
                q.push(L[t][i]);
                D[L[t][i]] = D[t] + 1;
            }
        }
    }
    
    if (D[W * H - 1] != mod) {
        output(D[W * H - 1], 0);
    }
    else{
        output("Odekakedekinai..", 0);
    }
    return 0;
}
0