結果

問題 No.971 いたずらっ子
ユーザー tnakao0123tnakao0123
提出日時 2020-01-18 19:41:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,128 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 91,704 KB
実行使用メモリ 8,560 KB
最終ジャッジ日時 2023-09-10 10:29:21
合計ジャッジ時間 4,876 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 3 ms
6,000 KB
testcase_08 RE -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
5,532 KB
testcase_12 AC 2 ms
5,524 KB
testcase_13 AC 2 ms
5,540 KB
testcase_14 RE -
testcase_15 AC 2 ms
5,692 KB
testcase_16 AC 3 ms
6,880 KB
testcase_17 AC 2 ms
5,548 KB
testcase_18 AC 2 ms
5,476 KB
testcase_19 AC 2 ms
5,480 KB
testcase_20 AC 2 ms
5,692 KB
testcase_21 AC 2 ms
5,520 KB
testcase_22 AC 2 ms
5,520 KB
testcase_23 AC 2 ms
5,556 KB
testcase_24 AC 2 ms
5,484 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 = 1000;
const int MAX_W = 1000;
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