結果
問題 | No.2276 I Want AC |
ユーザー | 👑 AngrySadEight |
提出日時 | 2023-04-21 21:52:52 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,004 bytes |
コンパイル時間 | 2,138 ms |
コンパイル使用メモリ | 141,256 KB |
実行使用メモリ | 15,040 KB |
最終ジャッジ日時 | 2024-11-06 15:22:20 |
合計ジャッジ時間 | 4,540 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | WA | - |
testcase_06 | AC | 2 ms
6,816 KB |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 2 ms
6,816 KB |
testcase_10 | AC | 2 ms
6,820 KB |
testcase_11 | AC | 7 ms
6,816 KB |
testcase_12 | AC | 17 ms
12,288 KB |
testcase_13 | AC | 7 ms
6,820 KB |
testcase_14 | AC | 4 ms
6,816 KB |
testcase_15 | AC | 10 ms
8,576 KB |
testcase_16 | AC | 9 ms
7,808 KB |
testcase_17 | AC | 16 ms
12,372 KB |
testcase_18 | AC | 12 ms
9,728 KB |
testcase_19 | AC | 3 ms
6,816 KB |
testcase_20 | AC | 18 ms
13,616 KB |
testcase_21 | AC | 8 ms
7,168 KB |
testcase_22 | AC | 5 ms
6,820 KB |
testcase_23 | AC | 20 ms
14,144 KB |
testcase_24 | AC | 20 ms
14,016 KB |
testcase_25 | AC | 20 ms
14,008 KB |
testcase_26 | AC | 19 ms
14,008 KB |
testcase_27 | AC | 19 ms
14,008 KB |
testcase_28 | AC | 16 ms
13,568 KB |
testcase_29 | AC | 16 ms
13,184 KB |
testcase_30 | AC | 19 ms
14,012 KB |
testcase_31 | AC | 15 ms
12,928 KB |
testcase_32 | AC | 18 ms
14,136 KB |
testcase_33 | AC | 18 ms
14,012 KB |
testcase_34 | AC | 20 ms
15,036 KB |
testcase_35 | AC | 14 ms
12,928 KB |
testcase_36 | AC | 14 ms
12,928 KB |
testcase_37 | AC | 18 ms
15,036 KB |
testcase_38 | AC | 14 ms
12,928 KB |
testcase_39 | AC | 14 ms
12,928 KB |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | AC | 17 ms
15,036 KB |
testcase_43 | AC | 18 ms
15,040 KB |
testcase_44 | AC | 16 ms
12,928 KB |
testcase_45 | AC | 19 ms
14,016 KB |
testcase_46 | AC | 20 ms
13,952 KB |
testcase_47 | AC | 16 ms
12,928 KB |
testcase_48 | AC | 16 ms
12,928 KB |
testcase_49 | AC | 19 ms
14,016 KB |
testcase_50 | AC | 19 ms
14,012 KB |
testcase_51 | AC | 20 ms
14,012 KB |
testcase_52 | AC | 21 ms
14,008 KB |
testcase_53 | AC | 19 ms
14,140 KB |
testcase_54 | AC | 17 ms
13,312 KB |
testcase_55 | AC | 16 ms
13,184 KB |
testcase_56 | AC | 15 ms
13,184 KB |
testcase_57 | AC | 15 ms
12,928 KB |
testcase_58 | WA | - |
ソースコード
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <iostream> #include <string> #include <vector> #include <algorithm> #include <functional> #include <stack> #include <queue> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <cmath> #include <cassert> #include <ctime> #include <utility> #include <random> #include <tuple> #include <bitset> // #include <atcoder/all> using namespace std; // using namespace atcoder; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--) #define repk(i, k, n) for (int i = k; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define mod1 1000000007 #define mod2 998244353 #define mod3 100000007 #define vi vector<int> #define vs vector<string> #define vc vector<char> #define vl vector<ll> #define vb vector<bool> #define vvi vector<vector<int>> #define vvc vector<vector<char>> #define vvl vector<vector<ll>> #define vvb vector<vector<bool>> #define vvvi vector<vector<vector<int>>> #define vvvl vector<vector<vector<ll>>> #define pii pair<int,int> #define pil pair<int,ll> #define pli pair<ll, int> #define pll pair<ll, ll> #define vpii vector<pair<int,int>> #define vpll vector<pair<ll,ll>> #define vvpii vector<vector<pair<int,int>>> #define vvpll vector<vector<pair<ll,ll>>> template<typename T> void debug(T e){ cerr << e << endl; } template<typename T> void debug(vector<T> &v){ rep(i, v.size()){ cerr << v[i] << " "; } cerr << endl; } template<typename T> void debug(vector<vector<T>> &v){ rep(i, v.size()){ rep(j, v[i].size()){ cerr << v[i][j] << " "; } cerr << endl; } } template<typename T> void debug(vector<pair<T, T>> &v){ rep(i,v.size()){ cerr << v[i].first << " " << v[i].second << endl; } } template<typename T> void debug(set<T> &st){ for (auto itr = st.begin(); itr != st.end(); itr++){ cerr << *itr << " "; } cerr << endl; } template<typename T> void debug(multiset<T> &ms){ for (auto itr = ms.begin(); itr != ms.end(); itr++){ cerr << *itr << " "; } cerr << endl; } template<typename T> void debug(map<T, T> &mp){ for (auto itr = mp.begin(); itr != mp.end(); itr++){ cerr << itr->first << " " << itr->second << endl; } } void debug_out(){ cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T){ cerr << H << " "; debug_out(T...); } ll my_pow(ll x, ll n, ll mod){ // 繰り返し二乗法.x^nをmodで割った余り. ll ret; if (n == 0){ ret = 1; } else if (n % 2 == 1){ ret = (x * my_pow((x * x) % mod, n / 2, mod)) % mod; } else{ ret = my_pow((x * x) % mod, n / 2, mod); } return ret; } ll inv(ll x, ll mod){ return my_pow(x, mod - 2, mod); } int main(){ ll N; cin >> N; string S; cin >> S; vl sum_a(N + 1); vl sum_c(N + 1); for (ll i = 0; i < N; i++){ if (S[i] == 'A') sum_a[i + 1] = sum_a[i] + 1; else sum_a[i + 1] = sum_a[i]; if (S[i] == 'C') sum_c[i + 1] = sum_c[i] + 1; else sum_c[i + 1] = sum_c[i]; } //debug(sum_a); //debug(sum_c); ll ans = 0; vl a_prd(N, 0); vl c_prd(N, 0); for (ll i = 0; i < N; i++){ if (S[i] == '?') a_prd[i] = sum_c[N] - sum_c[i]; if (S[i] == '?') c_prd[i] = sum_a[i + 1]; } ll hatena = 0; for (ll i = 0; i < N; i++){ if (S[i] == '?') hatena++; } //debug(a_prd); //debug(c_prd); vl a_prd_sum(N, 0); vl c_prd_sum(N, 0); a_prd_sum[N - 1] = a_prd[N - 1]; c_prd_sum[0] = c_prd[0]; for (ll i = 0; i < N - 1; i++){ c_prd_sum[i + 1] = c_prd_sum[i] + c_prd[i + 1]; } for (ll i = N - 2; i >= 0; i--){ a_prd_sum[i] = a_prd_sum[i + 1] + a_prd[i]; } //debug(a_prd_sum); //debug(c_prd_sum); vl hatenas(0); rep(i,N){ if (S[i] == '?') hatenas.push_back(i); } ll ans_base = 0; ll a = 0; for (ll i = 0; i < N; i++){ if (S[i] == 'A') a++; if (S[i] == 'C') ans_base += a; } ans = max(ans, ans_base); //debug(ans_base); for (ll i = 0; i < hatena; i++){ // どこまでを A で埋めるか if (i == 0){ // すべて C ll anssub = 0; anssub += c_prd_sum[N - 1]; ans = max(ans, anssub + ans_base); } else if (i == hatena){ ll anssub = 0; anssub += a_prd_sum[0]; ans = max(ans, anssub += ans_base); } else{ ll anssub = 0; anssub += (a_prd_sum[0] - a_prd_sum[hatenas[i]]); anssub += (c_prd_sum[N - 1] - c_prd_sum[hatenas[i - 1]]); anssub += i * (hatena - i); ans = max(ans, anssub += ans_base); } } cout << ans << endl; }