結果

問題 No.971 いたずらっ子
ユーザー recososorecososo
提出日時 2020-01-17 21:40:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 870 bytes
コンパイル時間 1,546 ms
コンパイル使用メモリ 169,540 KB
実行使用メモリ 22,508 KB
最終ジャッジ日時 2023-08-07 07:50:52
合計ジャッジ時間 4,629 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 229 ms
22,464 KB
testcase_01 AC 230 ms
22,484 KB
testcase_02 AC 172 ms
18,000 KB
testcase_03 AC 210 ms
22,408 KB
testcase_04 AC 196 ms
21,532 KB
testcase_05 AC 204 ms
22,508 KB
testcase_06 AC 158 ms
18,332 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 57 ms
8,372 KB
testcase_09 AC 54 ms
8,232 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,384 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