結果

問題 No.340 雪の足跡
ユーザー りあんりあん
提出日時 2016-02-09 02:31:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 236 ms / 1,000 ms
コード長 2,242 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 164,516 KB
実行使用メモリ 19,452 KB
最終ジャッジ日時 2023-10-21 20:28:07
合計ジャッジ時間 5,937 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int M = 1000000007;
    bool l[1000000][4];
    int dist[1000000];
    int th[1000000][2];

int main(){
    int w, h, n;
    scanf("%d%d%d", &w, &h, &n);
    for (int i = 0; i < 1000000; ++i){
        dist[i] = M;
        for (int j = 0; j < 2; ++j){
            th[i][j] = 0;
        }
        for (int j = 0; j < 4; ++j){
            l[i][j] = false;
        }
    }
    
    for (int i = 0; i < n; ++i){
        int m;
        scanf("%d", &m);
        int b[1001];
        for (int j = 0; j < m + 1; ++j){
            scanf("%d", &b[j]);
            if (j == 0)
                continue;
            
            int sm = b[j] > b[j - 1] ? b[j - 1] : b[j];
            int la = b[j] > b[j - 1] ? b[j] : b[j - 1];
            if (la - sm >= w){
                ++th[sm][0];
                --th[la][0];
            }
            else{
                ++th[sm][1];
                --th[la][1];
            }
        }
    }
    for (int i = 0; i < w; ++i){
        int sum = 0;
        for (int j = i; j < w * h; j += w){
            sum += th[j][0];
            if (sum > 0){
                l[j][0] = true;
                l[j + w][2] = true;
            }
        }
    }
    for (int i = 0; i < w * h; i += w){
        int sum = 0;
        for (int j = i; j < w + i; ++j){
            sum += th[j][1];
            if (sum > 0){
                l[j][1] = true;
                l[j + 1][3] = true;
            }
        }
    }
    queue<int> q;
    dist[0] = 0;
    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] >= M)
        printf("Odekakedekinai..\n");
    else
        printf("%d\n", dist[w * h - 1]);
}
0