結果

問題 No.971 いたずらっ子
ユーザー Konton7Konton7
提出日時 2020-01-18 00:04:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,267 bytes
コンパイル時間 2,001 ms
コンパイル使用メモリ 200,244 KB
実行使用メモリ 4,988 KB
最終ジャッジ日時 2023-09-08 09:07:18
合計ジャッジ時間 16,976 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

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 < h; 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