結果

問題 No.2276 I Want AC
ユーザー kabipoyokabipoyo
提出日時 2023-04-21 23:55:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,460 bytes
コンパイル時間 4,597 ms
コンパイル使用メモリ 255,512 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-04-24 09:44:45
合計ジャッジ時間 5,801 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 12 ms
7,808 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 7 ms
5,760 KB
testcase_16 AC 5 ms
5,504 KB
testcase_17 AC 9 ms
7,552 KB
testcase_18 AC 8 ms
6,528 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 11 ms
8,192 KB
testcase_21 AC 5 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 12 ms
8,320 KB
testcase_24 AC 12 ms
8,192 KB
testcase_25 AC 12 ms
8,192 KB
testcase_26 AC 11 ms
8,320 KB
testcase_27 AC 11 ms
8,192 KB
testcase_28 AC 10 ms
8,320 KB
testcase_29 AC 9 ms
8,320 KB
testcase_30 AC 11 ms
8,320 KB
testcase_31 AC 10 ms
8,320 KB
testcase_32 AC 11 ms
8,192 KB
testcase_33 AC 11 ms
8,320 KB
testcase_34 AC 11 ms
8,320 KB
testcase_35 AC 9 ms
8,320 KB
testcase_36 AC 9 ms
8,320 KB
testcase_37 AC 9 ms
8,192 KB
testcase_38 AC 9 ms
8,320 KB
testcase_39 AC 10 ms
8,320 KB
testcase_40 AC 9 ms
8,320 KB
testcase_41 AC 10 ms
8,192 KB
testcase_42 AC 9 ms
8,320 KB
testcase_43 AC 9 ms
8,320 KB
testcase_44 AC 11 ms
8,192 KB
testcase_45 AC 11 ms
8,192 KB
testcase_46 AC 12 ms
8,192 KB
testcase_47 AC 12 ms
8,320 KB
testcase_48 AC 12 ms
8,320 KB
testcase_49 AC 11 ms
8,320 KB
testcase_50 AC 11 ms
8,320 KB
testcase_51 AC 12 ms
8,320 KB
testcase_52 AC 11 ms
8,192 KB
testcase_53 AC 11 ms
8,320 KB
testcase_54 AC 10 ms
8,192 KB
testcase_55 AC 10 ms
8,320 KB
testcase_56 AC 9 ms
8,192 KB
testcase_57 AC 11 ms
8,320 KB
testcase_58 AC 10 ms
8,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef int64_t lint;
#define rep(i, n) for(int i=0; i<n; i++)
#define repx(i, l, n) for(int i=l; i<n; i++)
#define all(v) v.begin(), v.end()
#define show(x) cout << #x << ": " << x << endl;
#define list(x) cout << #x << ": " << x << "  ";
#define pb push_back
using vi = vector<lint>;
using vvi = vector<vector<lint>>;
template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline void drop(T x) { cout << x << endl; exit(0); }
template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }
constexpr lint LINF = LLONG_MAX/2;

int main() {
	lint N;
	string S;
	cin >> N >> S;

	lint a=0, b=0, c=0, x, y, z;
	vi A(N), B(N), C(N);
	rep(i, N) {
		if (S[i] == 'A') A[i]++;
		if (S[i] == '?') B[i]++;
		if (S[i] == 'C') C[i]++;
	}
	rep(i, N-1) {
		A[i+1] += A[i];
		B[i+1] += B[i];
		C[i+1] += C[i];
	}
	rep(i, N) {
		if (S[i] == 'A') a += C[N-1]-C[i];
		if (S[i] == 'A') a += B[N-1]-B[i];
	}
	c = a;
	rep(i, N) {
		if (S[i] == '?') a += C[N-1]-C[i];
		if (S[i] == '?') a += B[N-1]-B[i];
		if (S[i] == '?' && i) a -= B[i-1];
		if (S[i] == '?') a -= A[i];
		chmax(c, a);
	}
	cout << c << endl;
}
0