結果

問題 No.971 いたずらっ子
ユーザー recososorecososo
提出日時 2020-01-17 21:40:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 252 ms / 2,000 ms
コード長 870 bytes
コンパイル時間 1,660 ms
コンパイル使用メモリ 167,936 KB
実行使用メモリ 23,040 KB
最終ジャッジ日時 2024-04-25 01:56:53
合計ジャッジ時間 4,764 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 252 ms
22,784 KB
testcase_01 AC 243 ms
23,040 KB
testcase_02 AC 180 ms
17,920 KB
testcase_03 AC 230 ms
22,912 KB
testcase_04 AC 219 ms
21,632 KB
testcase_05 AC 220 ms
22,912 KB
testcase_06 AC 171 ms
18,560 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 60 ms
8,320 KB
testcase_09 AC 59 ms
8,448 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 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 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;
int main(){
    int h,w;cin >> h >> w;
    char a[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> a[i][j];
        }
    }
    vector<vector<int>> d(h,vector<int>(w,1e9));
    d[0][0]=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(i<h-1){
                if(a[i+1][j]=='.'){
                    d[i+1][j]=min(d[i+1][j],d[i][j]+1);
                }
                else{
                    d[i+1][j]=min(d[i+1][j],d[i][j]+1+i+1+j);
                }
            }
            if(j<w-1){
                if(a[i][j+1]=='.'){
                    d[i][j+1]=min(d[i][j+1],d[i][j]+1);
                }
                else{
                    d[i][j+1]=min(d[i][j+1],d[i][j]+1+i+j+1);
                }
            }
        }
    }
    cout << d[h-1][w-1] << endl;
}
0