結果
問題 | No.340 雪の足跡 |
ユーザー | Hachimori |
提出日時 | 2016-03-06 10:17:49 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 186 ms / 1,000 ms |
コード長 | 2,716 bytes |
コンパイル時間 | 888 ms |
コンパイル使用メモリ | 68,672 KB |
実行使用メモリ | 19,452 KB |
最終ジャッジ日時 | 2024-09-24 14:38:21 |
合計ジャッジ時間 | 4,695 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
19,308 KB |
testcase_01 | AC | 6 ms
19,312 KB |
testcase_02 | AC | 7 ms
19,180 KB |
testcase_03 | AC | 6 ms
19,184 KB |
testcase_04 | AC | 6 ms
19,436 KB |
testcase_05 | AC | 6 ms
19,312 KB |
testcase_06 | AC | 6 ms
19,440 KB |
testcase_07 | AC | 6 ms
19,308 KB |
testcase_08 | AC | 7 ms
19,316 KB |
testcase_09 | AC | 6 ms
19,312 KB |
testcase_10 | AC | 6 ms
19,308 KB |
testcase_11 | AC | 7 ms
19,192 KB |
testcase_12 | AC | 6 ms
19,312 KB |
testcase_13 | AC | 8 ms
19,316 KB |
testcase_14 | AC | 14 ms
19,312 KB |
testcase_15 | AC | 17 ms
19,320 KB |
testcase_16 | AC | 16 ms
19,304 KB |
testcase_17 | AC | 20 ms
19,312 KB |
testcase_18 | AC | 17 ms
19,316 KB |
testcase_19 | AC | 20 ms
19,316 KB |
testcase_20 | AC | 138 ms
19,308 KB |
testcase_21 | AC | 103 ms
19,320 KB |
testcase_22 | AC | 8 ms
19,440 KB |
testcase_23 | AC | 150 ms
19,196 KB |
testcase_24 | AC | 128 ms
19,192 KB |
testcase_25 | AC | 135 ms
19,452 KB |
testcase_26 | AC | 28 ms
19,324 KB |
testcase_27 | AC | 11 ms
19,196 KB |
testcase_28 | AC | 24 ms
19,324 KB |
testcase_29 | AC | 148 ms
19,192 KB |
testcase_30 | AC | 99 ms
19,448 KB |
testcase_31 | AC | 160 ms
19,324 KB |
testcase_32 | AC | 186 ms
19,200 KB |
testcase_33 | AC | 144 ms
19,452 KB |
testcase_34 | AC | 186 ms
19,324 KB |
testcase_35 | AC | 153 ms
19,196 KB |
testcase_36 | AC | 156 ms
19,200 KB |
コンパイルメッセージ
main.cpp: In function ‘void read()’: main.cpp:24:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | scanf("%d%d%d", &col, &row, &nRoute); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:33:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 33 | scanf("%d", &nPt); | ~~~~~^~~~~~~~~~~~ main.cpp:39:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 39 | scanf("%d", &v); | ~~~~~^~~~~~~~~~
ソースコード
#include<iostream> #include<vector> #include<queue> #include<cstring> #include<cstdio> #define r first #define c second using namespace std; typedef pair<int, int> Point; const int BUF = 1005; int dr[] = {1, 0, -1, 0}; int dc[] = {0, 1, 0, -1}; int row, col; bool canPass[BUF][BUF][4]; void read() { memset(canPass, 0, sizeof(canPass)); int nRoute; scanf("%d%d%d", &col, &row, &nRoute); static int hLineDiff[BUF][BUF]; static int vLineDiff[BUF][BUF]; memset(hLineDiff, 0 , sizeof(hLineDiff)); memset(vLineDiff, 0 , sizeof(vLineDiff)); for (int i = 0; i < nRoute; ++i) { int nPt; scanf("%d", &nPt); nPt++; vector<Point> ptList; for (int j = 0; j < nPt; ++j) { int v; scanf("%d", &v); ptList.push_back(Point(v / col, v % col)); } for (int j = 0; j + 1 < nPt; ++j) { Point &cur = ptList[j]; Point &nex = ptList[j + 1]; if (cur.r == nex.r) { ++hLineDiff[cur.r][min(cur.c, nex.c)]; --hLineDiff[cur.r][max(cur.c, nex.c)]; } else { ++vLineDiff[min(cur.r, nex.r)][cur.c]; --vLineDiff[max(cur.r, nex.r)][cur.c]; } } } for (int r = 0; r < row; ++r) { int sum = 0; for (int c = 0; c + 1 < col; ++c) { sum += hLineDiff[r][c]; if (sum > 0) { canPass[r][c][1] = canPass[r][c + 1][3] = true; } } } for (int c = 0; c < col; ++c) { int sum = 0; for (int r = 0; r + 1 < row; ++r) { sum += vLineDiff[r][c]; if (sum > 0) { canPass[r][c][0] = canPass[r + 1][c][2] = true; } } } } void work() { static int cost[BUF][BUF]; queue<Point> Q; memset(cost, -1, sizeof(cost)); cost[0][0] = 0; Q.push(Point(0, 0)); while (!Q.empty()) { Point cur = Q.front(); Q.pop(); if (cur.r == row - 1 && cur.c == col - 1) { cout << cost[cur.r][cur.c] << endl; return; } for (int i = 0; i < 4; ++i) { int nr = cur.r + dr[i]; int nc = cur.c + dc[i]; if (!canPass[cur.r][cur.c][i]) continue; if (!(0 <= nr && nr < row && 0 <= nc && nc < col)) continue; if (cost[nr][nc] != -1) continue; cost[nr][nc] = cost[cur.r][cur.c] + 1; Q.push(Point(nr, nc)); } } cout << "Odekakedekinai.." << endl; } int main() { read(); work(); return 0; }