結果
問題 | No.340 雪の足跡 |
ユーザー | mayoko_ |
提出日時 | 2016-01-29 23:17:30 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 274 ms / 1,000 ms |
コード長 | 3,406 bytes |
コンパイル時間 | 784 ms |
コンパイル使用メモリ | 90,600 KB |
実行使用メモリ | 25,472 KB |
最終ジャッジ日時 | 2024-09-21 18:39:50 |
合計ジャッジ時間 | 5,293 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 3 ms
5,376 KB |
testcase_12 | AC | 3 ms
5,376 KB |
testcase_13 | AC | 4 ms
5,376 KB |
testcase_14 | AC | 15 ms
8,704 KB |
testcase_15 | AC | 17 ms
9,728 KB |
testcase_16 | AC | 12 ms
7,424 KB |
testcase_17 | AC | 21 ms
9,984 KB |
testcase_18 | AC | 18 ms
9,984 KB |
testcase_19 | AC | 20 ms
9,984 KB |
testcase_20 | AC | 195 ms
25,472 KB |
testcase_21 | AC | 97 ms
5,376 KB |
testcase_22 | AC | 60 ms
25,088 KB |
testcase_23 | AC | 195 ms
25,344 KB |
testcase_24 | AC | 181 ms
25,216 KB |
testcase_25 | AC | 188 ms
25,216 KB |
testcase_26 | AC | 29 ms
8,320 KB |
testcase_27 | AC | 7 ms
5,376 KB |
testcase_28 | AC | 25 ms
8,576 KB |
testcase_29 | AC | 203 ms
23,936 KB |
testcase_30 | AC | 129 ms
14,720 KB |
testcase_31 | AC | 233 ms
23,552 KB |
testcase_32 | AC | 274 ms
25,088 KB |
testcase_33 | AC | 232 ms
25,088 KB |
testcase_34 | AC | 268 ms
25,216 KB |
testcase_35 | AC | 234 ms
25,216 KB |
testcase_36 | AC | 232 ms
25,088 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:48:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 48 | scanf("%d", &M); | ~~~~~^~~~~~~~~~ main.cpp:49:44: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 49 | for (int j = 0; j < M+1; j++) scanf("%d", B+j); | ~~~~~^~~~~~~~~~~
ソースコード
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> //#include<cctype> #include<climits> #include<iostream> #include<string> #include<vector> #include<map> //#include<list> #include<queue> #include<deque> #include<algorithm> //#include<numeric> #include<utility> #include<complex> //#include<memory> #include<functional> #include<cassert> #include<set> #include<stack> const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; const int MAX = 1111; const int INF = 1e9; int migi[MAX][MAX], hidari[MAX][MAX], up[MAX][MAX], down[MAX][MAX]; int B[MAX], dist[MAX][MAX]; int main() { int W, H, N; cin >> W >> H >> N; for (int y = 0; y < H; y++) { for (int x = 0; x < W; x++) migi[y][x] = hidari[y][x] = x; } for (int x = 0; x < W; x++) { for (int y = 0; y < H; y++) up[y][x] = down[y][x] = y; } for (int i = 0; i < N; i++) { int M; scanf("%d", &M); for (int j = 0; j < M+1; j++) scanf("%d", B+j); for (int j = 0; j < M; j++) { int y = B[j]/W, x = B[j]%W; int ny = B[j+1]/W, nx = B[j+1]%W; if (y == ny) { if (x < nx) { migi[y][x] = max(migi[y][x], nx); hidari[ny][nx] = min(hidari[ny][nx], x); } else { migi[ny][nx] = max(migi[ny][nx], x); hidari[y][x] = min(hidari[y][x], nx); } } else { if (y < ny) { up[y][x] = max(up[y][x], ny); down[ny][nx] = min(down[ny][nx], y); } else { up[ny][nx] = max(up[ny][nx], y); down[y][x] = min(down[y][x], ny); } } } } for (int y = 0; y < H; y++) { int maxi = 0; for (int x = 0; x < W; x++) { maxi = max(maxi, migi[y][x]); migi[y][x] = maxi; } int mini = W; for (int x = W-1; x >= 0; x--) { mini = min(mini, hidari[y][x]); hidari[y][x] = mini; } } for (int x = 0; x < W; x++) { int maxi = 0; for (int y = 0; y < H; y++) { maxi = max(maxi, up[y][x]); up[y][x] = maxi; } int mini = H; for (int y = H-1; y >= 0; y--) { mini = min(mini, down[y][x]); down[y][x] = mini; } } for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) dist[i][j] = INF; dist[0][0] = 0; queue<pii> que; que.push(pii(0, 0)); while (!que.empty()) { pii p = que.front(); que.pop(); int y = p.first, x = p.second; if (migi[y][x] > x && dist[y][x+1] > dist[y][x]+1) dist[y][x+1] = dist[y][x]+1, que.push(pii(y, x+1)); if (hidari[y][x] < x && dist[y][x-1] > dist[y][x]+1) dist[y][x-1] = dist[y][x]+1, que.push(pii(y, x-1)); if (up[y][x] > y && dist[y+1][x] > dist[y][x]+1) dist[y+1][x] = dist[y][x]+1, que.push(pii(y+1, x)); if (down[y][x] < y && dist[y-1][x] > dist[y][x]+1) dist[y-1][x] = dist[y][x]+1, que.push(pii(y-1, x)); } if (dist[H-1][W-1] >= INF) { cout << "Odekakedekinai.." << endl; } else { cout << dist[H-1][W-1] << endl; } return 0; }