結果

問題 No.971 いたずらっ子
ユーザー beetbeet
提出日時 2020-01-17 21:28:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 784 bytes
コンパイル時間 2,390 ms
コンパイル使用メモリ 200,244 KB
実行使用メモリ 42,240 KB
最終ジャッジ日時 2024-04-25 01:55:30
合計ジャッジ時間 3,976 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
42,240 KB
testcase_01 AC 113 ms
42,112 KB
testcase_02 AC 84 ms
30,720 KB
testcase_03 AC 102 ms
42,240 KB
testcase_04 AC 96 ms
39,936 KB
testcase_05 AC 101 ms
42,112 KB
testcase_06 AC 79 ms
30,848 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 28 ms
13,568 KB
testcase_09 AC 28 ms
13,056 KB
testcase_10 AC 3 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 1 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;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int h,w;
  cin>>h>>w;
  vector<string> st(h);
  for(Int i=0;i<h;i++) cin>>st[i];

  const Int INF = 1e15;
  vector< vector<Int> > dp(h,vector<Int>(w,INF));

  dp[0][0]=0;
  for(Int i=0;i<h;i++){
    for(Int j=0;j<w;j++){
      if(i+1<h){
        Int cst=1;
        if(st[i+1][j]=='k') cst+=i+j+1;
        chmin(dp[i+1][j],dp[i][j]+cst);
      }
      if(j+1<w){
        Int cst=1;
        if(st[i][j+1]=='k') cst+=i+j+1;
        chmin(dp[i][j+1],dp[i][j]+cst);
      }
    }
  }

  cout<<dp[h-1][w-1]<<endl;
  return 0;
}
0