結果
問題 | No.340 雪の足跡 |
ユーザー | norioc |
提出日時 | 2016-01-30 02:34:54 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,519 bytes |
コンパイル時間 | 413 ms |
コンパイル使用メモリ | 52,608 KB |
実行使用メモリ | 22,628 KB |
最終ジャッジ日時 | 2024-09-21 18:58:35 |
合計ジャッジ時間 | 4,769 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | WA | - |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | WA | - |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | WA | - |
testcase_13 | AC | 3 ms
5,376 KB |
testcase_14 | WA | - |
testcase_15 | AC | 17 ms
6,984 KB |
testcase_16 | WA | - |
testcase_17 | AC | 22 ms
7,236 KB |
testcase_18 | AC | 20 ms
7,108 KB |
testcase_19 | AC | 22 ms
7,240 KB |
testcase_20 | AC | 143 ms
22,604 KB |
testcase_21 | WA | - |
testcase_22 | AC | 24 ms
18,504 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 166 ms
22,344 KB |
testcase_26 | AC | 25 ms
6,016 KB |
testcase_27 | WA | - |
testcase_28 | AC | 23 ms
6,184 KB |
testcase_29 | AC | 224 ms
18,636 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 333 ms
22,600 KB |
testcase_33 | AC | 250 ms
22,500 KB |
testcase_34 | AC | 290 ms
22,600 KB |
testcase_35 | AC | 188 ms
22,628 KB |
testcase_36 | AC | 189 ms
22,552 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:68:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 68 | scanf("%d %d %d", &w, &h, &n); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:79:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 79 | scanf("%d", &m); | ~~~~~^~~~~~~~~~ main.cpp:82:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 82 | scanf("%d", &fm); | ~~~~~^~~~~~~~~~~ main.cpp:85:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 85 | scanf("%d", &to); | ~~~~~^~~~~~~~~~~
ソースコード
#include <cstdio> #include <vector> #include <map> #include <cassert> #include <queue> using namespace std; const int K = 1010; const int N = 1 << 0; const int E = 1 << 1; const int S = 1 << 2; const int W = 1 << 3; struct D { int row, col, cost; D(int row, int col, int cost) : row(row), col(col), cost(cost) {} }; int rev(int dir) { switch (dir) { case N: return S; case E: return W; case W: return E; case S: return N; } assert(false); return 0; } int calc(int rows, int cols, int g[][K][K]) { queue<D> q; q.push(D(0, 0, 0)); static int used[K][K] = {}; while (!q.empty()) { D d = q.front(); q.pop(); // printf("r:%d c:%d cost:%d\n", d.row, d.col, d.cost); if (d.row == rows-1 && d.col == cols-1) return d.cost; if (used[d.row][d.col]++) continue; // 上 if (d.row > 0 && g[0][d.row-1][d.col] > 0) q.push(D(d.row-1, d.col, d.cost+1)); // 下 if (d.row+1 < rows && g[0][d.row][d.col] > 0) q.push(D(d.row+1, d.col, d.cost+1)); // 右 if (d.col+1 < rows && g[1][d.row][d.col] > 0) q.push(D(d.row, d.col+1, d.cost+1)); // 左 if (d.col > 0 && g[1][d.col][d.col-1] > 0) q.push(D(d.row, d.col-1, d.cost+1)); } return -1; } int main() { int w, h, n; scanf("%d %d %d", &w, &h, &n); static int g[2][K][K] = {}; // [行or列どちら方向か][行][列] vector<pair<int, int> > cmap; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cmap.push_back(make_pair(i, j)); for (int i = 0; i < n; i++) { int m; scanf("%d", &m); int fm; scanf("%d", &fm); for (int j = 0; j < m; j++) { int to; scanf("%d", &to); // printf("%d -> %d\n", fm, to); int r1 = cmap[fm].first; int c1 = cmap[fm].second; int r2 = cmap[to].first; int c2 = cmap[to].second; // printf("(%d %d) -> (%d %d)\n", r1, c1, r2, c2); if (r1 != r2) { assert(c1 == c2); int fm = min(r1, r2); int to = max(r1, r2) + 1; g[0][fm][c1]++; g[0][to][c1]--; } else if (c1 != c2) { assert(r1 == r2); int fm = min(c1, c2); int to = max(c1, c2) + 1; g[1][r1][fm]++; g[1][r1][to]--; } else assert(false); fm = to; } } // 行方向を足し上げる for (int c = 0; c < w; c++) { for (int r = 1; r < h; r++) { g[0][r][c] += g[0][r-1][c]; } } // 列方向を足し上げる for (int r = 0; r < h; r++) { for (int c = 1; c < w; c++) { g[1][r][c] += g[1][r][c-1]; } } int ans = calc(h, w, g); if (ans == -1) { puts("Odekakedekinai.."); } else { printf("%d\n", ans); } }