結果

問題 No.2276 I Want AC
ユーザー kztasakztasa
提出日時 2023-04-22 11:42:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 4,206 bytes
コンパイル時間 4,335 ms
コンパイル使用メモリ 228,172 KB
実行使用メモリ 10,492 KB
最終ジャッジ日時 2024-04-24 16:26:59
合計ジャッジ時間 6,144 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h> 
#include <atcoder/all>
#define pub push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (ll i = int(b) - 1; i >= int(a); i--)
#define all(c) (c).begin(), (c).end()
using namespace std;
using namespace atcoder;
using ll = long long; using dd = double;
using Pll = pair<ll, ll>;
using    vll = vector<   ll>; using   vdd = vector< dd>;
using   vvll = vector<  vll>; using  vvdd = vector<vdd>;
using  vvvll = vector< vvll>; using vvvdd = vector<vvdd>;
using vvvvll = vector<vvvll>;
using  vchar = vector< char>;
using vvchar = vector<vchar>;
using mint = modint998244353;
using mint2 = modint1000000007;
using  vmint = vector< mint>; using  vmint2 = vector< mint2>;
using vvmint = vector<vmint>; using vvmint2 = vector<vmint2>;

constexpr long long INF = (1LL << 60);
constexpr double EPS = 1e-9;
constexpr double PI = 3.141592653589;

//////////////////////////////////////////////////////////

template <typename T>
bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}

template <typename T>
bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}

string zfill(int n, const int width)
{
	stringstream ss;
	ss << setw(width) << setfill('0') << n;
	return ss.str();
}

//1+2+3+…+N
ll OnetoN_sum(ll N) {
	return (N * (N + 1)) / 2;
}

template<typename T>
void outvec(vector<T> A) {
	ll N = A.size();
	rep(i, N) {
		cout << A[i] << " ";
	}
	cout << endl;
	return;
}

ll max(int x, ll y) { return max((ll)x, y); }
ll max(ll x, int y) { return max(x, (ll)y); }
int min(int x, ll y) { return min((ll)x, y); }
int min(ll x, int y) { return min(x, (ll)y); }

template<typename T = int>
std::map<T, ll> factorize(T n) {
	std::map<T, ll> factor_map;
	for (T i = 2; i * i <= n; i++) {
		while (!(n % i)) {
			factor_map[i]++; n /= i;
		}
	}
	if (n > 1) factor_map[n]++;
	return factor_map;
}

template<typename T = int>
vector<long long> divisor(T n) {
	vector<long long> ret;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end()); // 昇順に並べる
	return ret;
}

template<typename T = int>
bool isp(T num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) {
			return false;
		}
	}
	return true;
}

template<typename T = int>
vector<bool> Era(ll N) {
	vector<bool> isprime(N + 1, true);
	isprime[0] = isprime[1] = false;
	for (ll p = 2; p <= N; ++p) {
		if (!isprime[p]) continue;
		for (ll q = p * 2; q <= N; q += p) {
			isprime[q] = false;
		}
	}
	return isprime;
}

ll LIS(const std::vector<ll>& v) {
	std::vector<ll> dp;
	for (const auto& elem : v) {
		auto it = std::lower_bound(dp.begin(), dp.end(), elem);
		if (it == dp.end()) {
			dp.push_back(elem);
		}
		else {
			*it = elem;
		}
	}
	return dp.size();
}

vll Cumlative_Sum_of_Vector(vll A) {
	ll n = A.size();
	vll S(n + 1);
	S[0] = 0;
	rep(i, n) {
		S[i + 1] = S[i] + A[i];
	}
	return S;
}

bool Isin(ll a, ll b, ll H, ll W) {
	if (a >= 0 && a < H && b >= 0 && b < W) {
		return true;
	}
	else {
		return false;
	}
}
/////////////////////////////////////////////////////


int main() {
	//cout << fixed << setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	ll N; cin >> N;
	string S; cin >> S;
	vll sumA(N + 1), sumC(N + 1), sumH(N + 1);
	sumA[0] = 0;
	sumC[0] = 0;
	sumH[0] = 0;
	vector<ll> Hid;
	rep(i, N) {
		sumA[i + 1] = sumA[i];
		sumC[i + 1] = sumC[i];
		sumH[i + 1] = sumH[i];
		if (S[i] == 'A') {
			sumA[i + 1]++;
		}
		else if (S[i] == 'C') {
			sumC[i + 1]++;
		}
		else {
			sumH[i + 1]++;
			Hid.eb(i);
		}
	}
	ll ans = 0;
	rep(i, N) {
		if (S[i] == 'C' || S[i] == '?') {
			ans += sumA[i + 1];
		}
	}
	ll now = ans;
	for (auto a : Hid) {
		now += N - a - 1 - (sumA[N] - sumA[a]);
		now -= sumA[a] + sumH[a];
		chmax(ans, now);
	}
	cout << ans << endl;
}
0