結果

問題 No.971 いたずらっ子
ユーザー amaridekinaiamaridekinai
提出日時 2020-01-17 21:49:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 990 bytes
コンパイル時間 1,413 ms
コンパイル使用メモリ 164,476 KB
実行使用メモリ 23,396 KB
最終ジャッジ日時 2023-08-07 07:53:31
合計ジャッジ時間 4,399 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 196 ms
23,240 KB
testcase_01 AC 195 ms
23,288 KB
testcase_02 AC 149 ms
23,228 KB
testcase_03 AC 190 ms
23,396 KB
testcase_04 AC 180 ms
23,196 KB
testcase_05 AC 188 ms
23,232 KB
testcase_06 AC 148 ms
22,804 KB
testcase_07 AC 8 ms
19,760 KB
testcase_08 AC 55 ms
21,872 KB
testcase_09 AC 53 ms
21,844 KB
testcase_10 AC 8 ms
19,756 KB
testcase_11 AC 6 ms
19,728 KB
testcase_12 AC 7 ms
19,724 KB
testcase_13 AC 7 ms
19,716 KB
testcase_14 AC 8 ms
23,224 KB
testcase_15 AC 7 ms
19,732 KB
testcase_16 AC 7 ms
21,760 KB
testcase_17 AC 7 ms
19,724 KB
testcase_18 AC 7 ms
19,776 KB
testcase_19 AC 6 ms
19,796 KB
testcase_20 AC 7 ms
19,888 KB
testcase_21 AC 7 ms
19,924 KB
testcase_22 AC 6 ms
19,848 KB
testcase_23 AC 7 ms
19,768 KB
testcase_24 AC 7 ms
19,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

const int SIZE = 2020;

char s[SIZE][SIZE];

int dp[SIZE][SIZE];

int main(){ 
  
  int h,w; cin >> h >> w;
  
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){ 
      cin >> s[i][j];
    }
  }
  
  for(int i = 0; i < SIZE; i++){
    for(int j = 0; j < SIZE; j++){
      dp[i][j] = -1;
    }
  }
  
  dp[0][0] = 0;
  
  for(int i = 1; i < h; i++){
    if(s[i][0] == '.'){ dp[i][0] = dp[i-1][0]+1;}
    else{ dp[i][0] = dp[i-1][0]+1+0+i;}
  }
  
  for(int j = 1; j < w; j++){
    if(s[0][j] == '.'){ dp[0][j] = dp[0][j-1]+1;}
    else{ dp[0][j] = dp[0][j-1]+1+0+j;}
  }
  
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      
      if( dp[i][j] != -1){ continue;}
      
      if( s[i][j] == '.'){  
        dp[i][j] = min(dp[i-1][j],dp[i][j-1])+1;}
      else{
        dp[i][j] = min(dp[i-1][j],dp[i][j-1])+1+0+i+j;}
      
    }
  }
  
  cout << dp[h-1][w-1] << endl;
  
  return 0;
}
       
0