結果

問題 No.340 雪の足跡
ユーザー りあんりあん
提出日時 2016-02-09 03:18:51
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,672 bytes
コンパイル時間 2,239 ms
コンパイル使用メモリ 164,216 KB
実行使用メモリ 31,160 KB
最終ジャッジ日時 2023-10-21 20:31:27
合計ジャッジ時間 5,364 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,948 KB
testcase_01 WA -
testcase_02 AC 4 ms
9,948 KB
testcase_03 WA -
testcase_04 AC 3 ms
9,948 KB
testcase_05 AC 3 ms
9,948 KB
testcase_06 WA -
testcase_07 AC 3 ms
9,948 KB
testcase_08 WA -
testcase_09 AC 3 ms
9,948 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 93 ms
9,952 KB
testcase_22 AC 6 ms
9,948 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 145 ms
30,740 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |     scanf("%d%d%d", &w, &h, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         scanf("%d", &m);
      |         ~~~~~^~~~~~~~~~
main.cpp:14:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |             scanf("%d", &b[j]);
      |             ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define LM 1000000
int l[LM][4], dist[LM], th[LM][2];
int main(){
    int w, h, n;
    scanf("%d%d%d", &w, &h, &n);
    for (int i = 1; i < LM; ++i)
        dist[i] = LM;
    for (int i = 0; i < n; ++i){
        int m, b[1001];
        scanf("%d", &m);
        for (int j = 0; j < m + 1; ++j){
            scanf("%d", &b[j]);
            if (!j) continue;

            int sm = min(b[j], b[j - 1]);
            int la = max(b[j], b[j - 1]);
            ++th[sm][la - sm < w];
            --th[la][la - sm < w];
        }
    }
    for (int i = 0; i < w; ++i){
        int sum = 0;
        for (int j = i; j < w * h; j += w)
            if (sum += th[j][0] > 0)
                l[j][0] = l[j + w][2] = 1;
    }
    for (int i = 0; i < w * h; i += w){
        int sum = 0;
        for (int j = i; j < w + i; ++j)
            if (sum += th[j][1] > 0)
                l[j][1] = l[j + 1][3] = 1;
    }
    queue<int> q;
    q.push(0);
    while (!q.empty()){
        int p = q.front();
        q.pop();
        if (p == w * h - 1) break;

        int pd = dist[p] + 1;
        if (l[p][0] && dist[p + w] > pd){
            dist[p + w] = pd;
            q.push(p + w);
        }
        if (l[p][1] && dist[p + 1] > pd){
            dist[p + 1] = pd;
            q.push(p + 1);
        }
        if (l[p][2] && dist[p - w] > pd){
            dist[p - w] = pd;
            q.push(p - w);
        }
        if (l[p][3] && dist[p - 1] > pd){
            dist[p - 1] = pd;
            q.push(p - 1);
        }
    }
    if (dist[w * h - 1] >= LM)
        printf("Odekakedekinai..\n");
    else
        printf("%d\n", dist[w * h - 1]);
}
0