結果

問題 No.971 いたずらっ子
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2020-01-17 23:12:40
言語 C++17(clang)
(14.0.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,333 bytes
コンパイル時間 1,541 ms
コンパイル使用メモリ 108,404 KB
実行使用メモリ 556,520 KB
最終ジャッジ日時 2023-08-20 13:46:12
合計ジャッジ時間 8,422 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

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

typedef tuple<int,int,int,int> TP;

char dx[4]={1,0,-1,0};
char dy[4]={0,1,0,-1};
int h,w;
char a[2000][2000];
vector<vector<int>> ans;
priority_queue<TP, vector<TP>, greater<>> q;

void bfs() {
    q.emplace(0, 0, 0, 0);
    int c,kc,x,y;

    while(!q.empty()) {
        tie(c, kc, x,y) = q.top(); q.pop();
        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, xi, yi);
        }
    }
}

int main() {
    cin >> h >> w;
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            cin >> a[i][j];
        }
    }
    ans = vector<vector<int>>(h, vector<int> (w,-1));
    bfs();

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