結果
問題 | No.340 雪の足跡 |
ユーザー | 🍡yurahuna |
提出日時 | 2016-05-21 07:32:44 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 209 ms / 1,000 ms |
コード長 | 2,614 bytes |
コンパイル時間 | 1,532 ms |
コンパイル使用メモリ | 172,184 KB |
実行使用メモリ | 26,984 KB |
最終ジャッジ日時 | 2024-10-06 16:33:18 |
合計ジャッジ時間 | 5,165 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,820 KB |
testcase_01 | AC | 1 ms
6,820 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,816 KB |
testcase_05 | AC | 1 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 1 ms
6,820 KB |
testcase_09 | AC | 1 ms
6,816 KB |
testcase_10 | AC | 1 ms
6,816 KB |
testcase_11 | AC | 3 ms
6,820 KB |
testcase_12 | AC | 2 ms
6,816 KB |
testcase_13 | AC | 3 ms
6,820 KB |
testcase_14 | AC | 11 ms
8,528 KB |
testcase_15 | AC | 13 ms
8,408 KB |
testcase_16 | AC | 9 ms
8,148 KB |
testcase_17 | AC | 15 ms
8,912 KB |
testcase_18 | AC | 13 ms
8,788 KB |
testcase_19 | AC | 17 ms
8,936 KB |
testcase_20 | AC | 146 ms
26,720 KB |
testcase_21 | AC | 103 ms
6,820 KB |
testcase_22 | AC | 29 ms
26,752 KB |
testcase_23 | AC | 165 ms
26,676 KB |
testcase_24 | AC | 143 ms
26,728 KB |
testcase_25 | AC | 138 ms
26,700 KB |
testcase_26 | AC | 24 ms
6,816 KB |
testcase_27 | AC | 6 ms
6,816 KB |
testcase_28 | AC | 21 ms
8,020 KB |
testcase_29 | AC | 151 ms
22,368 KB |
testcase_30 | AC | 103 ms
15,180 KB |
testcase_31 | AC | 178 ms
25,188 KB |
testcase_32 | AC | 209 ms
26,968 KB |
testcase_33 | AC | 170 ms
26,984 KB |
testcase_34 | AC | 203 ms
26,984 KB |
testcase_35 | AC | 183 ms
26,972 KB |
testcase_36 | AC | 181 ms
26,816 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:68:13: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=] 68 | scanf("%d %d %d", &W, &H, &N); | ~^ ~~ | | | | int* long long int* | %lld main.cpp:68:16: warning: format ‘%d’ expects argument of type ‘int*’, but argument 3 has type ‘long long int*’ [-Wformat=] 68 | scanf("%d %d %d", &W, &H, &N); | ~^ ~~ | | | | int* long long int* | %lld main.cpp:68:19: warning: format ‘%d’ expects argument of type ‘int*’, but argument 4 has type ‘long long int*’ [-Wformat=] 68 | scanf("%d %d %d", &W, &H, &N); | ~^ ~~ | | | | int* long long int* | %lld main.cpp:73:17: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=] 73 | scanf("%d", &M); | ~^ ~~ | | | | | long long int* | int* | %lld main.cpp:78:21: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type*’ {aka ‘long long int*’} [-Wformat=] 78 | scanf("%d", &B[j]); | ~^ | | | int* | %lld main.cpp:68:10: 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:73:14: w
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long // <-----!!!!!!!!!!!!!!!!!!! #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n)-1;i>=0;i--) #define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--) #define all(a) (a).begin(),(a).end() typedef long long ll; typedef pair<int, int> P; int W, H, N; int e[1001][1001][2]; //(i, j) -> (i + 1, j), (i, j) -> (i, j + 1) inline P toNode(int n) { return P(n / W, n % W); } const int INF = 99999999; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; bool inside(int x, int y) { return 0 <= x && x < H && 0 <= y && y < W; } bool canGo(int x1, int y1, int x2, int y2) { if (x1 > x2 || y1 > y2) { swap(x1, x2); swap(y1, y2); } // assert(x1 <= x2 && y1 <= y2); return e[x1][y1][x1 == x2]; } int bfs(int sx, int sy, int gx, int gy) { queue<P> que; que.push(P(sx, sy)); vector<vector<int>> d(H, vector<int>(W, INF)); d[sx][sy] = 0; while (!que.empty()) { int x, y; tie(x, y) = que.front(); que.pop(); if (x == gx && y == gy) break; rep(k, 4) { int nx = x + dx[k], ny = y + dy[k]; if (!canGo(x, y, nx, ny)) continue; if (inside(nx, ny) && d[nx][ny] == INF) { que.push(P(nx, ny)); d[nx][ny] = d[x][y] + 1; } } } return d[gx][gy]; } signed main() { // std::ios::sync_with_stdio(false); // std::cin.tie(0); // cin >> W >> H >> N; scanf("%d %d %d", &W, &H, &N); rep(i, N) { int M; // cin >> M; scanf("%d", &M); vector<int> B(M + 1); rep(j, M + 1) { // cin >> B[j]; scanf("%d", &B[j]); } rep(j, M) { int x1, y1, x2, y2; tie(x1, y1) = toNode(B[j]); tie(x2, y2) = toNode(B[j + 1]); if (B[j] > B[j + 1]) { swap(x1, x2); swap(y1, y2); } if (y1 == y2) { e[x1][y1][0]++; e[x2][y2][0]--; } else { e[x1][y1][1]++; e[x2][y2][1]--; } } } rep(j, W) { rep(i, H) { e[i + 1][j][0] += e[i][j][0]; } } rep(i, H) { rep(j, W) { e[i][j + 1][1] += e[i][j][1]; } } int ans = bfs(0, 0, H - 1, W - 1); if (ans == INF) { cout << "Odekakedekinai.." << endl; } else { cout << ans << endl; } }