結果

問題 No.971 いたずらっ子
ユーザー y61mpnly61mpnl
提出日時 2020-01-17 23:49:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,173 bytes
コンパイル時間 1,653 ms
コンパイル使用メモリ 174,432 KB
実行使用メモリ 66,328 KB
最終ジャッジ日時 2023-09-08 08:41:41
合計ジャッジ時間 6,307 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 335 ms
66,324 KB
testcase_06 AC 258 ms
52,168 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct P {
        ll x, y, bs, dist;
};

int main(){
        ll h, w; scanf("%lld %lld", &h, &w);
        vector<vector<ll>> fig(h, vector<ll>(w));
        for(ll i=0; i<h; i++){
                string s; cin>>s;
                for(ll j=0; j<w; j++) fig[i][j] = (s[j]=='k');
        }

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

        vector<vector<ll>> ans(h, vector<ll>(w, 1e11));

        queue<P> que;
        P p = {0, 0, -1, 0};
        que.push(p);
        while(!que.empty()){
                p = que.front(); que.pop();
                if(fig[p.x][p.y]) p.dist += max(0ll, p.dist-p.bs*p.bs);
                if(ans[p.x][p.y]<=p.dist) continue;
                ans[p.x][p.y] = p.dist;
                for(ll i=0; i<2; i++){
                        ll tx = p.x-dx[i], ty = p.y-dy[i];
                        if(0<=tx && tx<h and 0<=ty && ty<w){
                                P np = {tx, ty, p.bs+fig[tx][ty], p.dist+1};
                                que.push(np);
                        }
                }
        }

        printf("%lld\n", ans[h-1][w-1]);
        return 0;
}
0