結果

問題 No.971 いたずらっ子
ユーザー coco18000coco18000
提出日時 2020-01-17 21:40:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,852 bytes
コンパイル時間 1,608 ms
コンパイル使用メモリ 171,552 KB
実行使用メモリ 116,260 KB
最終ジャッジ日時 2023-09-08 02:02:51
合計ジャッジ時間 8,532 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

string S[2005];
ll M[2005][2005];
ll T[2005][2005];
ll x[2] = {0, 1};
ll y[2] = {1, 0};

struct Data {
    pll g;
    ll c;
};

int main() {
    ll H, W;
    cin >> H >> W;
    REP(i, H) {
        cin >> S[i];
    }
    REP(i, H) {
        REP(j, W) {
            M[i][j] = INF;
            T[i][j] = INF;
        }
    }
    {
        T[0][0] = 0;
        queue<Data> q;
        q.push(Data{pll(0, 0), 0});
        while (!q.empty()) {
            auto t = q.front();
            q.pop();
            REP(i, 2) {
                ll nx = x[i] + t.g.first, ny = y[i] + t.g.second;
                if (nx < 0 || nx >= H || ny < 0 || ny >= W)
                    continue;
                ll cost = t.c + 1;
                if (T[nx][ny] <= cost)
                    continue;
                T[nx][ny] = cost;
                q.push(Data{pll(nx, ny), cost});
            }
        }
    }
    {
        M[0][0] = 0;
        queue<Data> q;
        q.push(Data{pll(0, 0), 0});
        while (!q.empty()) {
            auto t = q.front();
            q.pop();
            REP(i, 2) {
                ll nx = x[i] + t.g.first, ny = y[i] + t.g.second;
                if (nx < 0 || nx >= H || ny < 0 || ny >= W)
                    continue;
                ll cost = t.c + 1;
                if (S[nx][ny] == 'k')
                    cost += T[nx][ny];
                if (M[nx][ny] <= cost)
                    continue;
                M[nx][ny] = cost;
                q.push(Data{pll(nx, ny), cost});
            }
        }
    }
    cout << M[H - 1][W - 1] << endl;
    return 0;
}
0