結果
問題 |
No.2276 I Want AC
|
ユーザー |
![]() |
提出日時 | 2023-05-19 10:01:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 713 bytes |
コンパイル時間 | 362 ms |
コンパイル使用メモリ | 41,668 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-17 18:38:16 |
合計ジャッジ時間 | 2,097 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 |
ソースコード
/* -*- coding: utf-8 -*- * * 2276.cc: No.2276 I Want AC - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ typedef long long ll; /* global variables */ char s[MAX_N + 4]; /* subroutines */ /* main */ int main() { int n; scanf("%d%s", &n, s); ll sum = 0; int c = 0; for (int i = 0, a = 0; i < n; i++) { if (s[i] == 'A') a++; else sum += a, c++; } ll maxc = sum; for (int i = 0, a = 0; i < n; i++) { if (s[i] == '?') { sum -= a; a++, c--; sum += c; maxc = max(maxc, sum); } else if (s[i] == 'A') a++; else c--; } printf("%lld\n", maxc); return 0; }