結果
問題 | No.2276 I Want AC |
ユーザー |
|
提出日時 | 2023-04-21 21:45:27 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 3,647 bytes |
コンパイル時間 | 12,411 ms |
コンパイル使用メモリ | 307,148 KB |
最終ジャッジ日時 | 2025-02-12 11:22:20 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 |
ソースコード
#pragma GCC target ("avx2")#pragma GCC optimize ("O3")#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>#include <ext/pb_ds/assoc_container.hpp>using namespace __gnu_pbds;using namespace std;#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)#define all(x) (x).begin(), (x).end()#define rall(x) (x).rbegin(), (x).rend()#define endl '\n'typedef long long ll;#define mod1 (ll)1000000007#define mod2 (ll)998244353#define pll pair<ll,ll>typedef long double lb;typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;#define eps (lb)(1e-9)struct custom_hash {static uint64_t splitmix64(uint64_t x) {x += 0x9e3779b97f4a7c15;x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;x = (x ^ (x >> 27)) * 0x94d049bb133111eb;return x ^ (x >> 31);}size_t operator()(uint64_t x) const {static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();return splitmix64(x + FIXED_RANDOM);}};// Operator overloadstemplate<typename T1, typename T2> // cin >> pair<T1, T2>istream& operator>>(istream &istream, pair<T1, T2> &p) { return (istream >> p.first >> p.second); }template<typename T> // cin >> vector<T>istream& operator>>(istream &istream, vector<T> &v){for (auto &it : v)cin >> it;return istream;}template<typename T1, typename T2> // cout << pair<T1, T2>ostream& operator<<(ostream &ostream, const pair<T1, T2> &p) { return (ostream << p.first << " " << p.second); }template<typename T> // cout << vector<T>ostream& operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) cout << it << " "; return ostream; }// Utility functionstemplate <typename T>void print(T &&t) { cout << t << "\n"; }template <typename T, typename... Args>void print(T &&t, Args &&... args){cout << t << " ";print(forward<Args>(args)...);}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());ll random(ll p){ // gives random number in [0,p]return uniform_int_distribution<ll>(0, p)(rng);}ll dp[1<<18];ll calc[1<<18];ll n; string s;void solve();int main() {io;ll t=1,n=1;// cin>>t;while (t--){solve();}return 0;}void solve(){cin>>n>>s;// dp[i] -> total AC in s[0..i] if all ? are A// calc[i] -> total AC in s[i...] if all ? are Cll ans=0;ll cnt=0;for(ll i(0);i<n;++i){if(i==0){dp[i]=0;}else if(s[i]!='C'){dp[i]=dp[i-1];}else{dp[i]=cnt+dp[i-1];}cnt+=(s[i]!='C');ans=max(ans,dp[i]);}cnt=0;for(ll i(n-1);i>-1;--i){if(i==n-1){calc[i]=0;}else if(s[i]!='A'){calc[i]=calc[i+1];}else{calc[i]=cnt+calc[i+1];}cnt+=(s[i]!='A');ans=max(ans,calc[i]);}vector<ll>va(n),vc(n),p(n);for(ll i(0);i<n;++i){if(i==0){va[i]=(s[i]=='A');vc[i]=(s[i]=='C');p[i]=(s[i]=='?');}else{va[i]=(s[i]=='A')+va[i-1];vc[i]=(s[i]=='C')+vc[i-1];p[i]=(s[i]=='?')+p[i-1];}}for(ll i(0);i<(n-1);++i){ans=max(ans,dp[i]+calc[i+1]+(va[i]+p[i])*(vc.back()+p.back()-vc[i]-p[i]));}cout<<ans<<endl;}// Do not get stuck on a single approach for long, think of multiple ways