結果

問題 No.2276 I Want AC
ユーザー t98slidert98slider
提出日時 2023-04-21 21:41:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 522 ms / 2,000 ms
コード長 1,436 bytes
コンパイル時間 1,784 ms
コンパイル使用メモリ 166,384 KB
実行使用メモリ 8,480 KB
最終ジャッジ日時 2024-04-24 07:50:23
合計ジャッジ時間 18,904 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 139 ms
5,376 KB
testcase_12 AC 446 ms
7,816 KB
testcase_13 AC 137 ms
5,376 KB
testcase_14 AC 56 ms
5,376 KB
testcase_15 AC 200 ms
5,812 KB
testcase_16 AC 181 ms
5,672 KB
testcase_17 AC 355 ms
7,672 KB
testcase_18 AC 307 ms
6,604 KB
testcase_19 AC 11 ms
5,376 KB
testcase_20 AC 447 ms
8,344 KB
testcase_21 AC 160 ms
5,404 KB
testcase_22 AC 67 ms
5,376 KB
testcase_23 AC 522 ms
8,472 KB
testcase_24 AC 517 ms
8,472 KB
testcase_25 AC 506 ms
8,472 KB
testcase_26 AC 445 ms
8,476 KB
testcase_27 AC 423 ms
8,348 KB
testcase_28 AC 364 ms
8,352 KB
testcase_29 AC 340 ms
8,352 KB
testcase_30 AC 404 ms
8,344 KB
testcase_31 AC 326 ms
8,348 KB
testcase_32 AC 426 ms
8,348 KB
testcase_33 AC 408 ms
8,352 KB
testcase_34 AC 428 ms
8,476 KB
testcase_35 AC 252 ms
8,348 KB
testcase_36 AC 250 ms
8,220 KB
testcase_37 AC 254 ms
8,352 KB
testcase_38 AC 254 ms
8,352 KB
testcase_39 AC 256 ms
8,348 KB
testcase_40 AC 248 ms
8,476 KB
testcase_41 AC 253 ms
8,344 KB
testcase_42 AC 254 ms
8,476 KB
testcase_43 AC 253 ms
8,348 KB
testcase_44 AC 465 ms
8,352 KB
testcase_45 AC 459 ms
8,472 KB
testcase_46 AC 416 ms
8,352 KB
testcase_47 AC 459 ms
8,476 KB
testcase_48 AC 458 ms
8,476 KB
testcase_49 AC 405 ms
8,480 KB
testcase_50 AC 410 ms
8,352 KB
testcase_51 AC 410 ms
8,472 KB
testcase_52 AC 417 ms
8,472 KB
testcase_53 AC 419 ms
8,348 KB
testcase_54 AC 325 ms
8,476 KB
testcase_55 AC 303 ms
8,476 KB
testcase_56 AC 318 ms
8,348 KB
testcase_57 AC 302 ms
8,348 KB
testcase_58 AC 273 ms
8,472 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;
    cin >> n;
    string s, t = "AC{";
    cin >> s;
    auto f = [&](int mid){
        vector<array<ll,3>> dp(n + 1, {0, 0, 0});
        dp[0][0] = 1;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 3; j++){
                dp[i + 1][j] += dp[i][j];
                if(s[i] == '?'){
                    if(i < mid && j == 0) dp[i + 1][j + 1] += dp[i][j];
                    if(i >= mid && j == 1) dp[i + 1][j + 1] += dp[i][j];
                }else{
                    if(s[i] == t[j]) dp[i + 1][j + 1] += dp[i][j];
                }
            }
        }
        return dp[n][2];
    };
    ll ans = 0;
    int l = 0, r = n + 1, c1, c2;
    while(l + 3 < r){
        c1 = (2 * l + r) / 3;
        c2 = (l + 2 * r) / 3;
        ll v1 = f(c1), v2 = f(c2);
        ans = max(ans, max(v1, v2));
        if(v1 >= v2) r = c2;
        else l = c1;
    }
    for(int i = l - 10; i <= r + 10; i++){
        ans = max(ans, f(i));
    }
    l = 0, r = n + 1, c1, c2;
    while(l + 3 < r){
        c1 = (2 * l + r) / 3;
        c2 = (l + 2 * r) / 3;
        ll v1 = f(c1), v2 = f(c2);
        ans = max(ans, max(v1, v2));
        if(v1 > v2) r = c2;
        else l = c1;
    }
    for(int i = l - 10; i <= r + 10; i++){
        ans = max(ans, f(i));
    }
    cout << ans << '\n';
}
0