結果

問題 No.971 いたずらっ子
ユーザー totori_nyaatotori_nyaa
提出日時 2020-01-17 23:30:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,056 bytes
コンパイル時間 1,578 ms
コンパイル使用メモリ 170,680 KB
実行使用メモリ 131,484 KB
最終ジャッジ日時 2023-09-08 07:56:34
合計ジャッジ時間 8,485 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    
    int h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++) cin>>s[i];
    priority_queue<array<int,3>,vector<array<int,3>>,greater<array<int,3>>> q;
    q.push({0,0,0});
    int dx[2] = {1,0};
    int dy[2] = {0,1};
    int ans[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++) ans[i][j] = 1e9;
    }
    ans[0][0]=0;
    while(q.size()){
        array<int,3> p = q.top();
        q.pop();
        ans[p[1]][p[2]] = min(ans[p[1]][p[2]],p[0]);
        for(int i=0;i<2;i++){
            int x = p[1]+dx[i], y = p[2] + dy[i];
            if((unsigned int)x < h && (unsigned int)y < w){
                int ret;
                if(s[x][y]=='.') ret = p[0]+1;
                else{
                    ret = x+y+p[0]+1;
                }
                if(ans[x][y] > ret) q.push({ret,x,y});
            }
        }
    }
    cout << ans[h-1][w-1] << endl;

}
0