結果
| 問題 | No.2276 I Want AC | 
| コンテスト | |
| ユーザー |  siman | 
| 提出日時 | 2023-04-22 19:01:58 | 
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 313 ms / 2,000 ms | 
| コード長 | 1,183 bytes | 
| コンパイル時間 | 3,279 ms | 
| コンパイル使用メモリ | 142,200 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-07 07:01:40 | 
| 合計ジャッジ時間 | 13,798 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 56 | 
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
int N;
string S;
ll f(int x) {
  string T = S;
  int a_cnt = x;
  for (int i = 0; i < N; ++i) {
    if (S[i] != '?') continue;
    if (a_cnt > 0) {
      T[i] = 'A';
      --a_cnt;
    } else {
      T[i] = 'C';
    }
  }
  ll res = 0;
  ll cnt = 0;
  for (int i = 0; i < N; ++i) {
    if (T[i] == 'A') {
      ++cnt;
    } else {
      res += cnt;
    }
  }
  return res;
}
int main() {
  cin >> N;
  cin >> S;
  int A = 0;
  for (int i = 0; i < N; ++i) {
    if (S[i] == '?') {
      A++;
    }
  }
  int left = 0;
  int right = A;
  int loop_cnt = 100;
  for (int i = 0; i < loop_cnt; ++i) {
    int x = (2 * left + right) / 3;
    int y = (left + 2 * right) / 3;
    if (f(x) > f(y)) {
      right = y;
    } else {
      left = x;
    }
  }
  int base = (left + right) / 2;
  ll ans = 0;
  for (int x = max(0, base - 10); x <= min(A, base + 10); ++x) {
    ans = max(ans, f(x));
  }
  cout << ans << endl;
  return 0;
}
            
            
            
        