結果
問題 | No.2276 I Want AC |
ユーザー | Etis |
提出日時 | 2023-04-21 22:15:43 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 5,646 bytes |
コンパイル時間 | 2,183 ms |
コンパイル使用メモリ | 203,528 KB |
実行使用メモリ | 6,912 KB |
最終ジャッジ日時 | 2024-11-06 15:44:55 |
合計ジャッジ時間 | 4,141 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 3 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 5 ms
5,248 KB |
testcase_12 | AC | 10 ms
6,528 KB |
testcase_13 | AC | 4 ms
5,248 KB |
testcase_14 | AC | 3 ms
5,248 KB |
testcase_15 | AC | 6 ms
5,248 KB |
testcase_16 | AC | 5 ms
5,248 KB |
testcase_17 | AC | 9 ms
6,272 KB |
testcase_18 | AC | 7 ms
5,504 KB |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | AC | 9 ms
6,784 KB |
testcase_21 | AC | 5 ms
5,248 KB |
testcase_22 | AC | 3 ms
5,248 KB |
testcase_23 | AC | 10 ms
6,912 KB |
testcase_24 | AC | 10 ms
6,912 KB |
testcase_25 | AC | 10 ms
6,912 KB |
testcase_26 | AC | 10 ms
6,912 KB |
testcase_27 | AC | 11 ms
6,912 KB |
testcase_28 | AC | 9 ms
6,784 KB |
testcase_29 | AC | 9 ms
6,784 KB |
testcase_30 | AC | 11 ms
6,912 KB |
testcase_31 | AC | 8 ms
6,912 KB |
testcase_32 | AC | 11 ms
6,912 KB |
testcase_33 | AC | 11 ms
6,912 KB |
testcase_34 | AC | 9 ms
6,912 KB |
testcase_35 | AC | 6 ms
6,912 KB |
testcase_36 | AC | 7 ms
6,912 KB |
testcase_37 | AC | 7 ms
6,784 KB |
testcase_38 | AC | 7 ms
6,784 KB |
testcase_39 | AC | 7 ms
6,784 KB |
testcase_40 | AC | 7 ms
6,912 KB |
testcase_41 | AC | 6 ms
6,784 KB |
testcase_42 | AC | 6 ms
6,912 KB |
testcase_43 | AC | 7 ms
6,912 KB |
testcase_44 | AC | 9 ms
6,784 KB |
testcase_45 | AC | 10 ms
6,912 KB |
testcase_46 | AC | 9 ms
6,912 KB |
testcase_47 | AC | 10 ms
6,784 KB |
testcase_48 | AC | 10 ms
6,912 KB |
testcase_49 | AC | 10 ms
6,912 KB |
testcase_50 | AC | 11 ms
6,912 KB |
testcase_51 | AC | 9 ms
6,784 KB |
testcase_52 | AC | 9 ms
6,912 KB |
testcase_53 | AC | 10 ms
6,912 KB |
testcase_54 | AC | 8 ms
6,912 KB |
testcase_55 | AC | 7 ms
6,912 KB |
testcase_56 | AC | 7 ms
6,912 KB |
testcase_57 | AC | 7 ms
6,912 KB |
testcase_58 | AC | 7 ms
6,784 KB |
ソースコード
//#pragma GCC target("avx") //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; /*#include <atcoder/all> using namespace atcoder;//*/ //local debug #ifdef LOCAL #include <debug_print.hpp> #define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else #define debug(...) (static_cast<void>(0)) #endif #define overload4(a, b, c, d, e, ...) e //alias using ll = long long; using ull = unsigned long long; using ld = long double; //constants constexpr const int MOD = 998244353; constexpr const int MODM = 1000000007; struct {template <class T> constexpr operator T(){return std::numeric_limits<T>::max();}} INF; struct {template <class T> constexpr operator T() {return std::numeric_limits<T>::lowest();}} MINF; //rep(for-loop) macro #define rep2(i, n) for(ll i = 0; i < n; i++) #define rep3(i, k, n) for(ll i = k; i < n; i++) #define rep4(i, k, n, a) for(ll i = k; i < n; i += a) #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2)(__VA_ARGS__) #define rep1_2(i, n) for(ll i = 1; i <= n; i++) #define rep1_3(i, k, n) for(ll i = k; i <= n; i++) #define rep1_4(i, k, n, a) for(ll i = k; i <= n; i += a) #define rep1(...) overload4(__VA_ARGS__, rep1_4, rep1_3, rep1_2)(__VA_ARGS__) #define Rep2(i, n) for(ll i = n - 1; i >= 0; i--) #define Rep3(i, k, n) for(ll i = n - 1; i >= k; i--) #define Rep4(i, k, n, a) for(ll i = n - 1; i >= k; i -= a) #define Rep(...) overload4(__VA_ARGS__, Rep4, Rep3, Rep2)(__VA_ARGS__) #define Rep1_2(i, n) for(ll i = n; i >= 1; i--) #define Rep1_3(i, k, n) for(ll i = n; i >= k; i--) #define Rep1_4(i, k, n, a) for(ll i = n; i >= k; i -= a) #define Rep1(...) overload4(__VA_ARGS__, Rep1_4, Rep1_3, Rep1_2)(__VA_ARGS__) //vector #define vvecc(T, name, n, m) vector<vector<T>> name(n, vector<T>(m)) #define vvec(T, name, n) vector<vector<T>> name(n) #define vvecs(T, name, n, m, s) vector<vector<T>> name(n, vector<T>(m, s)) #define all(x) begin(x), end(x) #define MIN(v) *min_element(all(v)) #define MINI(v) distance(v.begin(), min_element(all(v))) #define MAX(v) *max_element(all(v)) #define MAXI(v) distance(v.begin(), max_element(all(v))) #define LB(v, x) distance((v).begin(), lower_bound(all(v), (x))) #define UB(v, x) distance((v).begin(), upper_bound(all(v), (x))) #define eb emplace_back #define pb pop_back template <class T> bool vec_same(vector<T> &a, vector<T> &b) {return (a.size() == b.size() && equal(all(a), b.begin()));} //data structure macro #define mp make_pair #define fi first #define se second #define pq(T) priority_queue<T> #define pqmin(T) priority_queue<T, vector<T>, greater<T>> #define pqminp(T1, T2) priority_queue<pair<T1, T2>, vector<pair<T1, T2>>, greater<pair<T1, T2>>> //output #define pl() cout << '\n' template<class T> void print(const T& a) {cout << a;} void printl(){} template<class T> void printl(const T& t){print(t); pl();} template<class Head, class... Tail> void printl(const Head& head, const Tail&... tail) {print(head); cout << " "; printl(tail...);} #define printd(x, d) cout << fixed << setprecision(d) << x << '\n' template <class T> void print_vec(vector<T> v) {for(T x : v) cout << x << " "; pl();} void Yes(bool a) {cout << (a ? "Yes" : "No") << '\n';} void Out2(bool a, string yes, string no) {cout << (a ? yes : no) << '\n';} //functions int ctoll(char c) {return c - '0';} char to_char(int x) {return x + '0';} template<class T> bool check_bit(T tar, T bit) {return ((tar & (int)Epow(2, bit)) != 0);} template<class... T> constexpr auto Emin(T... a){return min(initializer_list{a...});} template<class... T> constexpr auto Emax(T... a){return max(initializer_list{a...});} template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template<class T> bool overflow_if_add(T a, T b) {return (std::numeric_limits<T>::max() - a) < b;} template<class T> bool overflow_if_mul(T a, T b) {return (std::numeric_limits<T>::max() / a) < b;} template<class T> ll Epow(T x, T y) {ll ans = 1; for(int i = 0; i < y; i++) ans *= x; return ans;} //--------------------------------------------------------------------------------------------------- int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); int N; cin >> N; string S; cin >> S; string base = S; rep(i, S.size()) { if(S[i] == '?') S[i] = 'A'; } debug(S); vector<int> imosA(N + 2, 0), imosC(N + 2, 0); rep(i, S.size()) { if(S[i] == 'A') { imosA[i + 2]++; imosA[N + 1]--; } else if(S[i] == 'C') { imosC[0]++; imosC[i + 1]--; } } vector<int> Ax(N + 2, 0), Cx(N + 2, 0); //Ax[i] : i文字より左に何個Aがあるか(初期状態) Cx[i] : i文字目より右に何個Cがあるか(初期状態) Ax[0] = imosA[0]; Cx[0] = imosC[0]; rep1(i, N + 1) { Ax[i] = Ax[i - 1] + imosA[i]; Cx[i] = Cx[i - 1] + imosC[i]; } debug(Ax, Cx); ll ans = 0; rep(i, N) { if(S[i] == 'A') ans += Cx[i + 1]; } debug(ans); int effective_Cx = 0; ll cur = ans; Rep(i, N) { if(S[i] == 'A' && base[i] == '?') { cur += Ax[i + 1]; cur -= effective_Cx; effective_Cx++; } else if(S[i] == 'C') { effective_Cx++; } ans = max(ans, cur); } printl(ans); }