結果

問題 No.971 いたずらっ子
ユーザー shibh308shibh308
提出日時 2019-12-03 23:09:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 687 ms / 2,000 ms
コード長 1,064 bytes
コンパイル時間 2,460 ms
コンパイル使用メモリ 210,848 KB
実行使用メモリ 26,624 KB
最終ジャッジ日時 2024-04-25 01:54:58
合計ジャッジ時間 7,843 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 687 ms
26,624 KB
testcase_01 AC 681 ms
26,624 KB
testcase_02 AC 497 ms
19,072 KB
testcase_03 AC 525 ms
26,624 KB
testcase_04 AC 498 ms
25,216 KB
testcase_05 AC 527 ms
26,624 KB
testcase_06 AC 380 ms
18,944 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 123 ms
9,600 KB
testcase_09 AC 124 ms
9,344 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long;


signed main() {

    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    for(auto& x : a)
        cin >> x;

    vector<vector<int>> dist(h, vector<int>(w, 1e9));
    dist[0][0] = 0;
    priority_queue<tuple<int,int,int>, vector<tuple<int,int,int>>, greater<tuple<int,int,int>>> que;
    que.emplace(0, 0, 0);
    vector<int> dx{0, 1};
    vector<int> dy{1, 0};

    while(!que.empty()){
        int d, x, y;
        tie(d, x, y) = que.top();
        que.pop();
        if(dist[x][y] != d)
            continue;
        for(int i = 0; i < 2; ++i){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx < 0 || ny < 0 || nx >= h || ny >= w)
                continue;
            int nd = d + 1;
            if(a[nx][ny] == 'k'){
                nd = d + 1 + (nx + ny);
            }
            if(nd < dist[nx][ny]){
                dist[nx][ny] = nd;
                que.emplace(nd, nx, ny);
            }
        }
    }
    cout << dist.back().back() << endl;
}
0