結果

問題 No.971 いたずらっ子
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2020-01-17 22:58:56
言語 C++17(clang)
(14.0.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,417 bytes
コンパイル時間 1,550 ms
コンパイル使用メモリ 109,776 KB
実行使用メモリ 575,960 KB
最終ジャッジ日時 2023-08-20 13:45:38
合計ジャッジ時間 8,286 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
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 <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

typedef long long int64;
typedef pair<int,int> P;
typedef tuple<int,int,P> TP;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

void bfs(int h, int w, vector<string>& a, vector<vector<int64>>& ans) {
    priority_queue<TP, vector<TP>, greater<TP>> q;
    q.emplace(0, 0, P(0,0));

    while(!q.empty()) {
        int c,kc,x,y;
        P p;
        tie(c, kc, p) = q.top();
        q.pop();
        tie(x,y) = p;
        if (x < 0 || x >= w) continue;
        if (y < 0 || y >= h) continue;
        if (ans[y][x] >= 0) continue;
        ans[y][x] = c;
        if (a[y][x] == 'k') {
            c = c*2 + 1 - kc;
            kc++;
        }
        else c++;
        for (int i=0; i<4; i++) {
            int xi = x + dx[i];
            int yi = y + dy[i];
            if (xi < 0 || xi >= w) continue;
            if (yi < 0 || yi >= h) continue;
            q.emplace(c, kc, P(xi, yi));
        }
    }
}

int main() {
    int h,w;
    cin >> h >> w;
    vector<string> a(h);
    for (int i=0; i<h; i++) cin >> a[i];

    vector<vector<int64>> ans(h, vector<int64> (w,-1));
    bfs(h,w,a,ans);

    cout << ans[h-1][w-1] << endl;
}
0