結果

問題 No.2276 I Want AC
ユーザー milanis48663220milanis48663220
提出日時 2023-04-21 21:43:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,760 bytes
コンパイル時間 1,311 ms
コンパイル使用メモリ 120,676 KB
実行使用メモリ 24,004 KB
最終ジャッジ日時 2024-04-24 07:52:32
合計ジャッジ時間 3,852 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 21 ms
23,752 KB
testcase_36 AC 21 ms
23,748 KB
testcase_37 AC 21 ms
23,748 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 23 ms
23,744 KB
testcase_45 WA -
testcase_46 AC 24 ms
23,752 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

template<typename T>
class Cumsum{
    public:
    Cumsum(vector<T> v): v(v){
        n = v.size();
        v_cumsum = vector<T>(n+1, T(0));
        for(int i = 0; i < n; i++) v_cumsum[i+1] = v_cumsum[i]+v[i];
    }
    /**
     * v[l] + ... + v[r-1]
     */ 
    T sum(int l, int r){
        if(r <= l) return T(0);
        if(r > n) r = n;
        if(l < 0) l = 0;
        return v_cumsum[r]-v_cumsum[l];
    }
    private:
    int n;
    vector<T> v;
    vector<T> v_cumsum;
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    string s; cin >> s;
    vector<ll> a(n), c(n), q(n);
    vector<ll> v(n);
    int cnt = 0;
    ll f = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'A'){
            a[i] = 1;
            cnt++;
        }
        if(s[i] == 'C'){
            c[i] = 1;
            f += cnt;
        }
        if(s[i] == '?'){
            q[i] = 1;
            v[i] = cnt;
        }
    }
    cnt = 0;
    for(int i = n-1; i >= 0; i--){
        if(s[i] == 'C'){
            cnt++;
        }
        if(s[i] == '?'){
            v[i] += cnt;
        }
    }
    auto a_cumsum = Cumsum<ll>(a);
    auto c_cumsum = Cumsum<ll>(c);
    auto q_cumsum = Cumsum<ll>(q);
    auto v_cumsum = Cumsum<ll>(v);
    ll offset = f;
    ll mx = 0;
    for(int i = 0; i <= n; i++){
        ll a = q_cumsum.sum(0, i);
        ll c = q_cumsum.sum(i, n);
        chmax(mx, a*c+v_cumsum.sum(i, n));
        // cout << i << ' ' << a*c+v_cumsum.sum(i, n)+offset << endl;
    }
    cout << offset+mx << endl;
}
0