結果

問題 No.971 いたずらっ子
ユーザー i_mrhji_mrhj
提出日時 2020-01-19 19:57:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 1,331 bytes
コンパイル時間 746 ms
コンパイル使用メモリ 84,964 KB
実行使用メモリ 39,096 KB
最終ジャッジ日時 2023-08-07 08:02:55
合計ジャッジ時間 3,279 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
39,096 KB
testcase_01 AC 141 ms
38,928 KB
testcase_02 AC 104 ms
38,836 KB
testcase_03 AC 131 ms
38,964 KB
testcase_04 AC 118 ms
38,772 KB
testcase_05 AC 131 ms
38,848 KB
testcase_06 AC 96 ms
36,636 KB
testcase_07 AC 3 ms
6,368 KB
testcase_08 AC 32 ms
23,412 KB
testcase_09 AC 30 ms
23,352 KB
testcase_10 AC 3 ms
5,736 KB
testcase_11 AC 2 ms
5,492 KB
testcase_12 AC 2 ms
5,428 KB
testcase_13 AC 2 ms
5,388 KB
testcase_14 AC 18 ms
37,324 KB
testcase_15 AC 2 ms
5,612 KB
testcase_16 AC 3 ms
10,028 KB
testcase_17 AC 2 ms
5,532 KB
testcase_18 AC 2 ms
5,448 KB
testcase_19 AC 2 ms
5,440 KB
testcase_20 AC 2 ms
5,604 KB
testcase_21 AC 2 ms
5,516 KB
testcase_22 AC 2 ms
5,516 KB
testcase_23 AC 2 ms
5,460 KB
testcase_24 AC 2 ms
5,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;

ll powMod(ll x, ll n) {
  if (n == 0) return 1;
  ll r = powMod(x, n / 2);
  if (n % 2 == 0) return (r * r) % MOD;
  return (r * r % MOD) * x % MOD;
}

bool ijv(int i, int j, int h, int w) {
  if (0 <= i && i < h && 0 <= j && j < w) return true;
  return false;
}

char a[2010][2010];
ll s[2010][2010];

int main(void) {

  int h, w;
  cin >> h >> w;
 
  rep(i, h) cin >> a[i];

  
  rep(i, h) rep(j, w) s[i][j] = LLONG_MAX;
  s[0][0] = 0;
  for (int k = 1; k <= h + w - 2; k++) {
    rep(i, h) {
      int j = k - i;
      bool f1 = ijv(i - 1, j, h, w), f2 = ijv(i, j - 1, h, w);
      if (f1) s[i][j] = min(s[i][j], s[i - 1][j]);
      if (f2) s[i][j] = min(s[i][j], s[i][j - 1]);
      if (!f1 & !f2) continue;
      s[i][j]++;
      if (a[i][j] == 'k') s[i][j] += (ll)k;
    }
  }
  cout << s[h - 1][w - 1] << endl;

  return 0;

}
  
0