結果

問題 No.971 いたずらっ子
ユーザー totori_nyaatotori_nyaa
提出日時 2020-01-17 23:41:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 677 ms / 2,000 ms
コード長 1,124 bytes
コンパイル時間 1,683 ms
コンパイル使用メモリ 169,628 KB
実行使用メモリ 23,296 KB
最終ジャッジ日時 2024-04-25 02:04:42
合計ジャッジ時間 7,514 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 677 ms
23,296 KB
testcase_01 AC 675 ms
23,296 KB
testcase_02 AC 488 ms
18,176 KB
testcase_03 AC 541 ms
23,168 KB
testcase_04 AC 510 ms
22,144 KB
testcase_05 AC 542 ms
23,168 KB
testcase_06 AC 410 ms
18,688 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 130 ms
8,704 KB
testcase_09 AC 121 ms
8,320 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 2 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 1 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;
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();
        if(ans[p[1]][p[2]] < p[0]) continue;
        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){
                    ans[x][y] = ret;
                    q.push({ret,x,y});
                }
            }
        }
    }
    cout << ans[h-1][w-1] << endl;

}
0