結果
問題 | No.971 いたずらっ子 |
ユーザー | roaris |
提出日時 | 2020-01-17 21:57:10 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,248 bytes |
コンパイル時間 | 1,591 ms |
コンパイル使用メモリ | 170,872 KB |
実行使用メモリ | 25,068 KB |
最終ジャッジ日時 | 2023-09-08 02:43:28 |
合計ジャッジ時間 | 7,027 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 604 ms
24,684 KB |
testcase_06 | AC | 462 ms
24,248 KB |
testcase_07 | AC | 8 ms
6,044 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 5 ms
5,492 KB |
testcase_11 | AC | 2 ms
5,632 KB |
testcase_12 | AC | 2 ms
5,656 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 3 ms
8,416 KB |
testcase_17 | AC | 2 ms
5,424 KB |
testcase_18 | AC | 2 ms
5,344 KB |
testcase_19 | AC | 2 ms
5,436 KB |
testcase_20 | AC | 2 ms
5,608 KB |
testcase_21 | AC | 3 ms
5,712 KB |
testcase_22 | AC | 2 ms
5,412 KB |
testcase_23 | AC | 2 ms
5,424 KB |
testcase_24 | AC | 2 ms
5,432 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; #define INF 1000000 int H, W; char a[2100][2100]; int dist[2100][2100]; void dijkstra() { for (int i=0; i<H; i++) for (int j=0; j<W; j++) dist[i][j] = INF; dist[0][0] = 0; priority_queue<P, vector<P>, greater<P>> pq; pq.push(P(0, 0)); while (pq.size()) { P p = pq.top(); pq.pop(); int d = p.first; int v = p.second; int x = v/W, y = v%W; if (dist[x][y]<d) continue; if (x<H-1) { int w; if (a[x+1][y]=='k') w = x+y+2; else w = 1; if (dist[x+1][y]>dist[x][y]+w) { dist[x+1][y] = dist[x][y]+w; pq.push(P(dist[x+1][y], W*(x+1)+y)); } } if (y<W-1) { int w; if (a[x][y+1]=='k') w = x+y+2; else w = 1; if (dist[x][y+1]>dist[x][y]+w) { dist[x][y+1] = dist[x][y]+w; pq.push(P(dist[x][y+1], W*x+y+1)); } } } } int main() { cin >> H >> W; for (int i=0; i<H; i++) for (int j=0; j<W; j++) cin >> a[i][j]; dijkstra(); cout << dist[H-1][W-1] << endl; }