結果

問題 No.971 いたずらっ子
ユーザー どららどらら
提出日時 2020-01-17 21:57:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,155 bytes
コンパイル時間 829 ms
コンパイル使用メモリ 78,376 KB
実行使用メモリ 113,032 KB
最終ジャッジ日時 2023-09-08 02:43:36
合計ジャッジ時間 7,570 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 <iostream>
#include <queue>
#include <vector>
#define ll long long

using namespace std;

struct ST {
    int y, x;
    int dist;
    int tm;
    ST():dist(-1),tm(-1){}
    ST(int y, int x, int dist, int tm):y(y),x(x),dist(dist),tm(tm){}
};
bool operator<(const ST& a, const ST& b){
    if(a.tm == b.tm) return a.dist < b.dist;
    return a.tm < b.tm;
}

ST dp[2005][2005];

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> field;
    for(int i=0; i<H; i++){
        string s;
        cin >> s;
        field.push_back(s);
    }
    
    queue<ST> que;
    que.push(ST(0, 0, 0, 0));
    
    while(!que.empty()){
        ST st = que.front(); que.pop();
        if(dp[st.y][st.x].tm == -1 || st < dp[st.y][st.x]){
            dp[st.y][st.x] = st;
            
            if(st.x+1<W){
                que.push(ST(st.y, st.x+1, st.dist+1, st.tm + 1 + (field[st.y][st.x+1]=='k'?st.dist+1:0)));
            }
            if(st.y+1<H){
                que.push(ST(st.y+1, st.x, st.dist+1, st.tm + 1 + (field[st.y+1][st.x]=='k'?st.dist+1:0)));
            }
        }
    }
    
    cout << dp[H-1][W-1].tm << endl;
    
    return 0;
}
0