結果

問題 No.971 いたずらっ子
ユーザー karinohitokarinohito
提出日時 2021-09-06 00:15:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 842 bytes
コンパイル時間 1,654 ms
コンパイル使用メモリ 172,680 KB
実行使用メモリ 35,328 KB
最終ジャッジ日時 2024-04-25 02:18:15
合計ジャッジ時間 3,672 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
35,328 KB
testcase_01 AC 142 ms
35,200 KB
testcase_02 AC 110 ms
27,264 KB
testcase_03 AC 111 ms
35,200 KB
testcase_04 AC 102 ms
33,280 KB
testcase_05 AC 110 ms
35,328 KB
testcase_06 AC 86 ms
28,032 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 30 ms
11,904 KB
testcase_09 AC 29 ms
11,392 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 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 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using Graph = vector<vector<ll>>;
ll mod=1e9+7;

int main() {
    ll H,W;
    cin>>H>>W;
    vector<vector<bool>> C(H+1,vector<bool> (W+1,false));
    rep(h,H){
        string S;
        cin>>S;
        rep(w,W){
            if(S[w]=='k')C[h][w]=true;
        }
    }
    vector<vll> DP(H+1,vll(W+1,1e18));
    DP[0][0]=0;
    rep(h,H){
        rep(w,W){
            if(C[h][w+1])DP[h][w+1]=min(DP[h][w+1],DP[h][w]+2+h+w);
            else DP[h][w+1]=min(DP[h][w+1],DP[h][w]+1);

            if(C[h+1][w])DP[h+1][w]=min(DP[h+1][w],DP[h][w]+2+h+w);
            else DP[h+1][w]=min(DP[h+1][w],DP[h][w]+1);
        }
    }
    cout<<DP[H-1][W-1]<<endl;
}
0