結果

問題 No.971 いたずらっ子
ユーザー recososorecososo
提出日時 2020-01-17 21:36:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 866 bytes
コンパイル時間 1,750 ms
コンパイル使用メモリ 168,608 KB
実行使用メモリ 22,928 KB
最終ジャッジ日時 2023-09-08 01:52:12
合計ジャッジ時間 4,744 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 202 ms
22,508 KB
testcase_06 AC 159 ms
18,340 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 4 ms
4,384 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,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+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);
                }
            }
        }
    }
    cout << d[h-1][w-1] << endl;
}
0