結果

問題 No.2278 Time Bomb Game 2
ユーザー t98slidert98slider
提出日時 2023-04-21 23:12:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 274 ms / 2,000 ms
コード長 2,465 bytes
コンパイル時間 1,682 ms
コンパイル使用メモリ 175,248 KB
実行使用メモリ 401,920 KB
最終ジャッジ日時 2024-04-24 09:40:22
合計ジャッジ時間 5,433 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 6 ms
8,960 KB
testcase_07 AC 30 ms
36,336 KB
testcase_08 AC 30 ms
38,208 KB
testcase_09 AC 53 ms
64,024 KB
testcase_10 AC 27 ms
32,940 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 59 ms
68,268 KB
testcase_14 AC 41 ms
49,704 KB
testcase_15 AC 45 ms
54,184 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 8 ms
11,264 KB
testcase_18 AC 26 ms
33,708 KB
testcase_19 AC 28 ms
36,904 KB
testcase_20 AC 274 ms
401,792 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 46 ms
55,980 KB
testcase_24 AC 53 ms
65,320 KB
testcase_25 AC 40 ms
48,556 KB
testcase_26 AC 37 ms
44,584 KB
testcase_27 AC 45 ms
56,576 KB
testcase_28 AC 18 ms
24,704 KB
testcase_29 AC 36 ms
46,248 KB
testcase_30 AC 35 ms
42,148 KB
testcase_31 AC 4 ms
7,296 KB
testcase_32 AC 26 ms
33,064 KB
testcase_33 AC 267 ms
401,920 KB
testcase_34 AC 51 ms
61,736 KB
testcase_35 AC 56 ms
68,008 KB
testcase_36 AC 23 ms
29,096 KB
testcase_37 AC 25 ms
33,448 KB
testcase_38 AC 28 ms
37,804 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 39 ms
49,452 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 32 ms
40,360 KB
testcase_44 AC 4 ms
5,376 KB
testcase_45 AC 12 ms
17,152 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 60 ms
70,700 KB
testcase_49 AC 39 ms
49,064 KB
testcase_50 AC 7 ms
9,984 KB
testcase_51 AC 47 ms
55,468 KB
testcase_52 AC 3 ms
5,376 KB
testcase_53 AC 38 ms
45,096 KB
testcase_54 AC 7 ms
10,496 KB
testcase_55 AC 10 ms
13,696 KB
testcase_56 AC 2 ms
5,376 KB
testcase_57 AC 22 ms
29,608 KB
testcase_58 AC 4 ms
7,296 KB
testcase_59 AC 45 ms
55,852 KB
testcase_60 AC 50 ms
62,248 KB
testcase_61 AC 5 ms
7,168 KB
testcase_62 AC 57 ms
67,620 KB
testcase_63 AC 2 ms
5,376 KB
testcase_64 AC 2 ms
5,376 KB
testcase_65 AC 2 ms
5,376 KB
testcase_66 AC 2 ms
5,376 KB
testcase_67 AC 2 ms
5,376 KB
testcase_68 AC 2 ms
5,376 KB
testcase_69 AC 2 ms
5,376 KB
testcase_70 AC 2 ms
5,376 KB
testcase_71 AC 1 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--;
    if(t <= 500){
        vector<vector<int>> dp(n, vector<int>(501, -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';
        return 0;
    }
    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();
    t %= 50;
    t += 50;
    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