結果

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

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <set>

using namespace::std;




int main() {
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  
  long long best = 0;
  unordered_map<char, long long> t;
  for (char x : s) {
    if (x == 'C' || x == '?') best += t['A'];
    ++t[x];
  }
  
  long long b = best;
  unordered_map<char, long long> c;
  for (char x : s) {
    if (x == '?') {
      b -= c['A'] + c['?'];
      b += (t['C'] - c['C']) + (t['?'] - c['?'] - 1);
    }
    best = max(b, best);
    ++c[x];
  }
  
  cout << best << endl;
  
  

  

  
  return 0;
}
0