結果

問題 No.971 いたずらっ子
コンテスト
ユーザー totori_nyaa
提出日時 2020-01-17 22:00:23
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
MLE  
実行時間 -
コード長 1,151 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,268 ms
コンパイル使用メモリ 190,992 KB
実行使用メモリ 1,076,724 KB
最終ジャッジ日時 2026-03-12 05:37:22
合計ジャッジ時間 32,039 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 WA * 6 TLE * 3 MLE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    
    ll h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++) cin>>s[i];
    priority_queue<array<int,4>,vector<array<int,4>>,greater<array<int,4>>> q;
    bool used[h*w]={};
    q.push({0,0,0,0});
    int dx[4] = {1,0,-1,0};
    int dy[4] = {0,1,0,-1};
    int ans[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++) ans[i][j] = 1e9;
    }
    ans[0][0]=0;
    while(q.size()){
        array<int,4> p = q.top();
        q.pop();
        ans[p[1]][p[2]] = min(ans[p[1]][p[2]],p[0]);
        for(int i=0;i<4;i++){
            int cnt = p[3];
            int x = p[1]+dx[i], y = p[2] + dy[i];
            if((unsigned int)x < h && (unsigned int)y < w){
                int ret;
                if(s[x][y]=='.') ret = p[0]+1;
                else{
                    ret = p[0]*2+2-cnt;
                    cnt++;
                }
                if(ans[x][y] > ret) q.push({ret,x,y,cnt});
            }
        }
    }
    cout << ans[h-1][w-1] << endl;

}
0