結果
問題 | No.340 雪の足跡 |
ユーザー | 🍡yurahuna |
提出日時 | 2016-05-21 07:32:44 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 257 ms / 1,000 ms |
コード長 | 2,614 bytes |
コンパイル時間 | 1,888 ms |
コンパイル使用メモリ | 170,220 KB |
実行使用メモリ | 27,008 KB |
最終ジャッジ日時 | 2024-04-16 04:40:47 |
合計ジャッジ時間 | 6,012 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 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 | 1 ms
5,376 KB |
testcase_11 | AC | 3 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 3 ms
5,376 KB |
testcase_14 | AC | 14 ms
6,272 KB |
testcase_15 | AC | 15 ms
6,528 KB |
testcase_16 | AC | 12 ms
5,376 KB |
testcase_17 | AC | 19 ms
6,784 KB |
testcase_18 | AC | 16 ms
6,784 KB |
testcase_19 | AC | 20 ms
6,912 KB |
testcase_20 | AC | 172 ms
26,880 KB |
testcase_21 | AC | 111 ms
5,376 KB |
testcase_22 | AC | 34 ms
26,752 KB |
testcase_23 | AC | 179 ms
26,624 KB |
testcase_24 | AC | 165 ms
26,732 KB |
testcase_25 | AC | 159 ms
26,752 KB |
testcase_26 | AC | 27 ms
5,376 KB |
testcase_27 | AC | 7 ms
5,376 KB |
testcase_28 | AC | 23 ms
5,632 KB |
testcase_29 | AC | 207 ms
20,992 KB |
testcase_30 | AC | 141 ms
15,360 KB |
testcase_31 | AC | 222 ms
25,088 KB |
testcase_32 | AC | 257 ms
26,980 KB |
testcase_33 | AC | 212 ms
26,984 KB |
testcase_34 | AC | 253 ms
27,008 KB |
testcase_35 | AC | 208 ms
27,008 KB |
testcase_36 | AC | 212 ms
27,008 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; } }