結果
問題 |
No.971 いたずらっ子
|
ユーザー |
![]() |
提出日時 | 2020-01-17 21:28:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 202 ms / 2,000 ms |
コード長 | 784 bytes |
コンパイル時間 | 2,751 ms |
コンパイル使用メモリ | 198,524 KB |
最終ジャッジ日時 | 2025-01-08 18:19:15 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#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; }