結果

問題 No.340 雪の足跡
ユーザー asi1024asi1024
提出日時 2016-02-19 23:02:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 385 ms / 1,000 ms
コード長 1,326 bytes
コンパイル時間 2,545 ms
コンパイル使用メモリ 167,416 KB
実行使用メモリ 70,564 KB
最終ジャッジ日時 2023-10-23 18:35:58
合計ジャッジ時間 8,501 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
31,092 KB
testcase_01 AC 11 ms
31,092 KB
testcase_02 AC 11 ms
29,056 KB
testcase_03 AC 11 ms
31,092 KB
testcase_04 AC 11 ms
31,092 KB
testcase_05 AC 11 ms
29,044 KB
testcase_06 AC 11 ms
31,092 KB
testcase_07 AC 11 ms
29,044 KB
testcase_08 AC 11 ms
31,092 KB
testcase_09 AC 11 ms
31,092 KB
testcase_10 AC 11 ms
31,092 KB
testcase_11 AC 12 ms
31,128 KB
testcase_12 AC 12 ms
31,188 KB
testcase_13 AC 12 ms
31,228 KB
testcase_14 AC 31 ms
33,400 KB
testcase_15 AC 33 ms
33,540 KB
testcase_16 AC 24 ms
32,200 KB
testcase_17 AC 38 ms
33,904 KB
testcase_18 AC 35 ms
33,928 KB
testcase_19 AC 38 ms
33,904 KB
testcase_20 AC 175 ms
45,448 KB
testcase_21 AC 106 ms
31,124 KB
testcase_22 AC 21 ms
39,092 KB
testcase_23 AC 248 ms
70,564 KB
testcase_24 AC 132 ms
39,504 KB
testcase_25 AC 187 ms
53,044 KB
testcase_26 AC 34 ms
31,492 KB
testcase_27 AC 16 ms
31,100 KB
testcase_28 AC 36 ms
32,524 KB
testcase_29 AC 251 ms
55,584 KB
testcase_30 AC 184 ms
50,304 KB
testcase_31 AC 343 ms
67,200 KB
testcase_32 AC 384 ms
70,564 KB
testcase_33 AC 347 ms
70,564 KB
testcase_34 AC 385 ms
70,564 KB
testcase_35 AC 359 ms
70,564 KB
testcase_36 AC 359 ms
70,564 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |   scanf("%d%d%d", &W, &H, &N);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:17:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |     int M; scanf("%d", &M);
      |            ~~~~~^~~~~~~~~~
main.cpp:19:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |     REP(j,M+1) scanf("%d", &B[j]);
      |                ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

const int INF = 1e9;

int row[1024][1024], column[1024][1024];
vector<int> g[1024000];

int main() {
  int W, H, N;
  scanf("%d%d%d", &W, &H, &N);
  REP(i,N) {
    int M; scanf("%d", &M);
    vector<int> B(M+1);
    REP(j,M+1) scanf("%d", &B[j]);
    REP(j,M) {
      int a = B[j], b = B[j+1];
      if (a > b) swap(a, b);
      if (b - a < W) { ++row[a/W][a%W]; --row[b/W][b%W]; }
      else { ++column[a/W][a%W]; --column[b/W][b%W]; }
    }
  }
  REP(i,H) REP(j,W-1) row[i][j+1] += row[i][j];
  REP(i,H-1) REP(j,W) column[i+1][j] += column[i][j];
  REP(i,H) REP(j,W) {
    if (row[i][j]) {
      g[i*W+j].push_back(i*W+j+1);
      g[i*W+j+1].push_back(i*W+j);
    }
    if (column[i][j]) {
      g[i*W+j].push_back(i*W+j+W);
      g[i*W+j+W].push_back(i*W+j);
    }
  }
  vector<int> dist(H * W, INF);
  dist[0] = 0;
  queue<int> que;
  que.push(0);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int i: g[v]) {
      if (dist[i] < INF) continue;
      dist[i] = dist[v] + 1;
      que.push(i);
    }
  }
  //for (int i: dist) cout << i << endl;
  if (dist[H * W - 1] == INF) cout << "Odekakedekinai.." << endl;
  else cout << dist[H * W - 1] << endl;
  return 0;
}
0