結果

問題 No.2276 I Want AC
ユーザー 👑 nu50218nu50218
提出日時 2023-04-21 21:53:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,529 bytes
コンパイル時間 3,454 ms
コンパイル使用メモリ 227,840 KB
実行使用メモリ 15,012 KB
最終ジャッジ日時 2024-04-27 04:47:41
合計ジャッジ時間 5,814 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 9 ms
6,944 KB
testcase_12 AC 24 ms
14,344 KB
testcase_13 AC 9 ms
6,940 KB
testcase_14 AC 6 ms
6,940 KB
testcase_15 AC 13 ms
9,060 KB
testcase_16 AC 12 ms
8,908 KB
testcase_17 AC 25 ms
14,212 KB
testcase_18 AC 18 ms
9,424 KB
testcase_19 AC 3 ms
6,940 KB
testcase_20 AC 31 ms
14,764 KB
testcase_21 AC 10 ms
8,588 KB
testcase_22 AC 7 ms
6,944 KB
testcase_23 AC 25 ms
14,916 KB
testcase_24 AC 26 ms
14,832 KB
testcase_25 AC 26 ms
14,832 KB
testcase_26 AC 32 ms
14,744 KB
testcase_27 AC 27 ms
14,892 KB
testcase_28 AC 18 ms
14,840 KB
testcase_29 AC 16 ms
14,744 KB
testcase_30 AC 26 ms
14,772 KB
testcase_31 AC 12 ms
14,916 KB
testcase_32 AC 28 ms
14,852 KB
testcase_33 AC 24 ms
14,820 KB
testcase_34 AC 36 ms
14,816 KB
testcase_35 AC 20 ms
14,808 KB
testcase_36 AC 9 ms
14,808 KB
testcase_37 AC 43 ms
15,012 KB
testcase_38 AC 21 ms
14,860 KB
testcase_39 AC 21 ms
14,848 KB
testcase_40 AC 8 ms
14,912 KB
testcase_41 AC 9 ms
14,848 KB
testcase_42 AC 43 ms
14,744 KB
testcase_43 AC 44 ms
14,988 KB
testcase_44 AC 17 ms
14,860 KB
testcase_45 AC 27 ms
14,840 KB
testcase_46 AC 35 ms
14,828 KB
testcase_47 AC 16 ms
14,888 KB
testcase_48 AC 16 ms
14,848 KB
testcase_49 AC 26 ms
14,868 KB
testcase_50 AC 26 ms
14,896 KB
testcase_51 AC 35 ms
14,848 KB
testcase_52 AC 35 ms
14,824 KB
testcase_53 AC 28 ms
14,708 KB
testcase_54 AC 20 ms
14,932 KB
testcase_55 AC 21 ms
14,900 KB
testcase_56 AC 19 ms
14,852 KB
testcase_57 AC 21 ms
14,748 KB
testcase_58 AC 11 ms
14,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef LOCAL
#include <local.hpp>
#else
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2")
#include <bits/stdc++.h>
#define debug(...) ((void)0)
#define postprocess(...) ((void)0)
#endif

#include "atcoder/segtree.hpp"

using namespace std;
using ll = long long;
using ld = long double;

using Sclass = pair<ll, ll>;

Sclass op(Sclass a, Sclass b) {
    return {a.first + b.first, a.second + b.second};
}
Sclass e() {
    return {0, 0};
}

void solve([[maybe_unused]] ll test) {
    ll N;
    cin >> N;

    string S;
    cin >> S;

    vector<pair<ll, ll>> a(N);
    for (ll i = 0; i < N; i++) {
        switch (S[i]) {
            case 'A':
                a[i] = {1, 0};
                break;

            case 'C':
                a[i] = {0, 1};
                break;

            default:
                a[i] = {0, 1};
                break;
        }
    }

    atcoder::segtree<Sclass, op, e> st(a);

    ll ans = 0;

    ll tmp = 0;
    for (ll i = 0; i < N; i++) {
        if (S[i] == 'A') tmp += st.prod(i + 1, N).second;
    }
    ans = max(ans, tmp);

    for (ll i = 0; i < N; i++) {
        if (S[i] != '?') continue;

        st.set(i, {1, 0});

        tmp -= st.prod(0, i).first;
        tmp += st.prod(i + 1, N).second;

        ans = max(ans, tmp);
    }

    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) {
        solve(i);
    }

    postprocess();
}
0