結果

問題 No.2278 Time Bomb Game 2
ユーザー t98slidert98slider
提出日時 2023-04-21 23:07:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,713 bytes
コンパイル時間 1,789 ms
コンパイル使用メモリ 173,832 KB
実行使用メモリ 70,700 KB
最終ジャッジ日時 2024-04-24 09:08:26
合計ジャッジ時間 9,950 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 29 ms
32,936 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 59 ms
68,268 KB
testcase_14 AC 42 ms
49,748 KB
testcase_15 AC 46 ms
54,180 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 30 ms
36,904 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 WA -
testcase_24 WA -
testcase_25 RE -
testcase_26 AC 38 ms
44,712 KB
testcase_27 AC 50 ms
56,740 KB
testcase_28 AC 22 ms
24,704 KB
testcase_29 AC 40 ms
46,248 KB
testcase_30 AC 36 ms
42,020 KB
testcase_31 AC 5 ms
7,424 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 58 ms
61,608 KB
testcase_35 AC 60 ms
67,884 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 33 ms
37,816 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 RE -
testcase_42 AC 3 ms
5,376 KB
testcase_43 RE -
testcase_44 AC 4 ms
5,376 KB
testcase_45 RE -
testcase_46 AC 3 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 WA -
testcase_49 AC 42 ms
49,064 KB
testcase_50 RE -
testcase_51 AC 49 ms
55,460 KB
testcase_52 AC 2 ms
5,376 KB
testcase_53 RE -
testcase_54 WA -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 WA -
testcase_59 RE -
testcase_60 WA -
testcase_61 RE -
testcase_62 AC 64 ms
67,624 KB
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
testcase_69 RE -
testcase_70 RE -
testcase_71 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, t, mn = 1 << 30;
    string s, s2;
    cin >> n >> k >> t >> s;
    k--;
    for(int i = k; i + 1 < n; i++){
        if(s[i] != s[i + 1]){
            mn = min(mn, i + 1 - k);
            break;
        }
    }
    for(int i = k; i >= 1; i--){
        if(s[i] != s[i - 1]){
            mn = min(mn, k - (i - 1));
            break;
        }
    }
    if(mn > t){
        cout << (s[k] == 'A' ? "Bob" : "Alice") << '\n';
        return 0;
    }
    char tmp = s[k];
    s[k] = 'C';
    vector<pair<char,int>> b;
    for(int i = 0; i < n; ){
        int p = i;
        while(i < n && s[i] == s[p]) i++;
        b.emplace_back(s[p], i - p);
    }
    
    for(int i = 0; i < b.size(); i++){
        char c;
        int v;
        tie(c, v) = b[i];
        if(c == 'C'){
            k = s2.size();
            s2 += tmp;
            continue;
        }
        s2 += string(v % 2 + (v >= 2) * 2, c);
    }
    swap(s, s2);
    n = s.size();

    vector<vector<int>> dp(n, vector<int>(101, -1));
    function<int(int,int)> rec = [&](int i, int t){
        if(t == 0) return s[i] == 'A' ? 0 : 1;
        if(dp[i][t] != -1) return dp[i][t];
        if(s[i] == 'A'){
            if(i >= 1 && rec(i - 1, t - 1) == 1) return dp[i][t] = 1;
            if(i + 1 < n && rec(i + 1, t - 1) == 1) return dp[i][t] = 1;
            return dp[i][t] = 0;
        }
        if(i >= 1 && rec(i - 1, t - 1) == 0) return dp[i][t] = 0;
        if(i + 1 < n && rec(i + 1, t - 1) == 0) return dp[i][t] = 0;
        return dp[i][t] = 1;
    };
    cout << (rec(k, t) ? "Alice" : "Bob") << '\n';
}
0