結果

問題 No.971 いたずらっ子
ユーザー milanis48663220milanis48663220
提出日時 2020-06-04 01:29:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,510 bytes
コンパイル時間 814 ms
コンパイル使用メモリ 90,184 KB
実行使用メモリ 38,912 KB
最終ジャッジ日時 2024-05-05 08:37:37
合計ジャッジ時間 8,008 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 662 ms
38,528 KB
testcase_04 AC 628 ms
36,864 KB
testcase_05 AC 649 ms
38,528 KB
testcase_06 AC 499 ms
34,432 KB
testcase_07 WA -
testcase_08 AC 162 ms
17,664 KB
testcase_09 AC 154 ms
17,280 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 WA -
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 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 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, Pii> P;

int H, W;
char a[2000][2000];
ll dist[2000][2000];
const ll INF = 1e15;
int dh[4] = {-1, 1, 0, 0};
int dw[4] = {0, 0, -1, 1};

bool in_field(int h, int w){
    return h >= 0 && h < H && w >= 0 && w < W;
}

void dijkstra(){
    priority_queue<P, vector<P>, greater<P>> que;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            dist[i][j] = INF;
        }
    }
    dist[0][0] = 0;
    que.push(P(0, Pii(0, 0)));
    while(!que.empty()){
        P p = que.top();que.pop();
        Pii v = p.second;
        int h = v.first, w = v.second;
        if(dist[h][w] < p.first) continue;
        for(int i = 0; i < 4; i++){
            int h_to = h+dh[i], w_to = w+dw[i];
            if(!in_field(h_to, w_to)) continue;
            ll cost = (a[h_to][w_to] == '.' ? 1 : (2+h+w));
            if(dist[h][w] + cost < dist[h_to][w_to]){
                dist[h_to][w_to] = dist[h][w] + cost;
                que.push(P(dist[h_to][w_to], Pii(h_to, w_to)));
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    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;
}
0