結果

問題 No.971 いたずらっ子
ユーザー Konton7Konton7
提出日時 2020-01-18 00:05:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 1,267 bytes
コンパイル時間 2,145 ms
コンパイル使用メモリ 199,500 KB
実行使用メモリ 26,648 KB
最終ジャッジ日時 2023-08-07 07:58:55
合計ジャッジ時間 4,000 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
26,520 KB
testcase_01 AC 96 ms
26,580 KB
testcase_02 AC 71 ms
18,952 KB
testcase_03 AC 92 ms
26,648 KB
testcase_04 AC 85 ms
25,508 KB
testcase_05 AC 90 ms
26,628 KB
testcase_06 AC 69 ms
18,840 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 26 ms
9,552 KB
testcase_09 AC 25 ms
9,232 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,388 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

// #define DEBUG

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int h, w;
    const int inf = 1e9;
    cin >> h >> w;
    string field[h];
    int dist[h][w];
    int ans[h][w];
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            ans[i][j] = inf;
    ans[0][0] = 0;

    for (int i = 0; i < h; i++)
        cin >> field[i];

    for (int i = 1; i < h; i++)
    {
        ans[i][0] = ans[i - 1][0] + 1;
        if (field[i][0] == 'k')
            ans[i][0] += i;
    }

    for (int j = 1; j < w; j++)
    {
        ans[0][j] = ans[0][j - 1] + 1;
        if (field[0][j] == 'k')
            ans[0][j] += j;
    }

    for (int i = 1; i < h; i++)
    {
        for (int j = 1; j < w; j++)
        {
            ans[i][j] = min(ans[i][j - 1], ans[i - 1][j]) + 1;
            if (field[i][j] == 'k')
                ans[i][j] += i + j;
        }
    }

    // for (int i = 0; i < h; i++)
    // {
    //     for (int j = 0; j < w; j++)
    //         cout << ans[i][j] << " ";
    //     cout << endl;
    // }
    cout << ans[h-1][w-1] << endl;
    return 0;
}
0