結果
| 問題 |
No.2276 I Want AC
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-21 21:53:18 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 45 ms / 2,000 ms |
| コード長 | 1,529 bytes |
| コンパイル時間 | 11,302 ms |
| コンパイル使用メモリ | 283,180 KB |
| 最終ジャッジ日時 | 2025-02-12 11:33:52 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 56 |
ソースコード
#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();
}