結果

問題 No.971 いたずらっ子
ユーザー NOSSNOSS
提出日時 2020-01-17 21:46:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 831 ms / 2,000 ms
コード長 1,220 bytes
コンパイル時間 2,186 ms
コンパイル使用メモリ 174,872 KB
実行使用メモリ 42,368 KB
最終ジャッジ日時 2024-04-25 01:58:43
合計ジャッジ時間 9,308 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 831 ms
42,368 KB
testcase_01 AC 827 ms
42,240 KB
testcase_02 AC 601 ms
30,848 KB
testcase_03 AC 678 ms
42,240 KB
testcase_04 AC 632 ms
40,064 KB
testcase_05 AC 676 ms
42,368 KB
testcase_06 AC 500 ms
30,976 KB
testcase_07 AC 7 ms
5,376 KB
testcase_08 AC 160 ms
13,440 KB
testcase_09 AC 152 ms
13,056 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 AC 3 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 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 <bits/stdc++.h>
using namespace std;

using ll = long long int;
using P = pair<int,int>;
using P3 = pair<ll,P>;
using PP = pair<P, P>;
constexpr int INF = 1<<30;
constexpr ll MOD = (1e9)+7;
constexpr int di[] = {0,1,0,-1};
constexpr int dj[] = {1,0,-1,0};

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i=0;i<h;i++){
        cin >> s[i];
    }
    vector<vector<ll> > d(h, vector<ll>(w, INF));
    d[0][0] = 0;
    priority_queue<P3,vector<P3>,greater<P3> > que;
    que.push(make_pair(0LL,P(0,0)));
    while(!que.empty()){
        auto p = que.top();
        que.pop();
        int i = p.second.first, j = p.second.second;
        if(d[i][j] < p.first) continue;
        for(int k=0;k<2;k++){
            int ni = i+di[k], nj=j+dj[k];
            if(ni<0||ni>=h)continue;
            if(nj<0||nj>=w)continue;
            ll nd;
            if(s[ni][nj] == '.'){
                nd = d[i][j] + 1;
            }else{
                nd = d[i][j] + 1 + ni + nj;
            }
            if(d[ni][nj] > nd){
                d[ni][nj] = nd;
                que.push(make_pair(d[ni][nj],P(ni,nj)));
            }
        }
    }
    cout << d[h-1][w-1] << endl;
    return 0;
}
0