結果

問題 No.2276 I Want AC
ユーザー achapi
提出日時 2023-04-21 22:57:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 744 bytes
コンパイル時間 2,638 ms
コンパイル使用メモリ 196,328 KB
最終ジャッジ日時 2025-02-12 12:23:42
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	string t = s;
	for (int i = 0; i < n; i++){
		if (t[i] == '?'){
			t[i] = 'C';
		}
	}
	vector<long long> dp(2);
	for (int i = 0; i < n; i++){
		if (t[i] == 'A'){
			dp[0]++;
		}
		if (t[i] == 'C'){
			dp[1] += dp[0];
		}
	}
	long long m = dp[1];
	long long ans = m;
	vector<int> a(n + 1);
	vector<int> b(n + 1);
	for (int i = 1; i <= n; i++){
		if (t[i - 1] == 'A' or s[i - 1] == '?'){
			a[i]++;
		}
		if (t[i - 1] == 'C' or s[i - 1] == '?'){
			b[i]++;
		}
		a[i] += a[i - 1];
		b[i] += b[i - 1];
	}
	for (int i = 0; i < n; i++){
		if (s[i] == '?'){
			m -= a[i];
			m += b[n] - b[i + 1];
		}
		ans = max(ans, m);
	}
	cout << ans << endl;
}
0