結果
問題 |
No.971 いたずらっ子
|
ユーザー |
![]() |
提出日時 | 2020-01-17 23:49:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 95 ms / 2,000 ms |
コード長 | 1,245 bytes |
コンパイル時間 | 943 ms |
コンパイル使用メモリ | 78,028 KB |
実行使用メモリ | 38,400 KB |
最終ジャッジ日時 | 2024-11-07 11:35:13 |
合計ジャッジ時間 | 2,795 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#include <stdio.h> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <algorithm> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <iterator> #include <assert.h> #pragma warning(disable:4996) typedef long long ll; #define MIN(a, b) ((a)>(b)? (b): (a)) #define MAX(a, b) ((a)<(b)? (b): (a)) #define LINF 9223300000000000000 #define INF 2140000000 const long long MOD = 1000000007; //const long long MOD = 998244353; using namespace std; char str[2005][2005]; int dx[2]={1,0}; int dy[2]={0,1}; ll dp[2005][2005]; int main(int argc, char* argv[]) { int h,w; scanf("%d%d", &h, &w); int i,j,k; for(i=0; i<h; i++) { scanf("%s", str[i]); } for(i=0; i<=h; i++) { for(j=0; j<=w; j++) { dp[i][j]=LINF; } } dp[0][0]=0; for(i=0; i<h; i++) { for(j=0; j<w; j++) { for(k=0; k<2; k++) { int i2=i+dx[k], j2=j+dy[k]; if(i2>=h || j2>=w) continue; int add=(str[i2][j2]=='k'? i2+j2+1: 1); dp[i2][j2]=MIN(dp[i2][j2],dp[i][j]+add); } } } printf("%lld\n", dp[h-1][w-1]); return 0; }