結果

問題 No.971 いたずらっ子
ユーザー tnakao0123tnakao0123
提出日時 2020-01-18 19:42:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,128 bytes
コンパイル時間 996 ms
コンパイル使用メモリ 95,124 KB
実行使用メモリ 23,424 KB
最終ジャッジ日時 2024-04-25 02:08:26
合計ジャッジ時間 2,593 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
23,296 KB
testcase_01 AC 62 ms
23,296 KB
testcase_02 AC 50 ms
23,296 KB
testcase_03 AC 43 ms
23,296 KB
testcase_04 AC 40 ms
22,272 KB
testcase_05 AC 42 ms
23,424 KB
testcase_06 AC 34 ms
20,864 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 16 ms
13,696 KB
testcase_09 AC 16 ms
13,568 KB
testcase_10 AC 2 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 10 ms
15,616 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,632 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 971.cc:  No.971 いたずらっ子 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 2000;
const int MAX_W = 2000;
const int INF = 1 << 30;

/* typedef */

/* global variables */

char fs[MAX_H][MAX_W + 4];
int ds[MAX_H][MAX_W];

/* subroutines */

inline void setmin(int &a, int b) { if (a > b) a = b; }

/* main */

int main() {
  int h, w;
  scanf("%d%d", &h, &w);

  for (int y = 0; y < h; y++) {
    scanf("%s", fs[y]);
    fill(ds[y], ds[y] + w, INF);
  }
  ds[0][0] = 0;

  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++) {
      int vd = ds[y][x] + 1;
      if (fs[y][x] == 'k') vd += y + x;

      if (y + 1 < h) setmin(ds[y + 1][x], vd);
      if (x + 1 < w) setmin(ds[y][x + 1], vd);
    }

  printf("%d\n", ds[h - 1][w - 1]);
  return 0;
}
0