結果
問題 | No.2276 I Want AC |
ユーザー |
![]() |
提出日時 | 2023-05-19 09:50:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 869 bytes |
コンパイル時間 | 386 ms |
コンパイル使用メモリ | 42,496 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-17 18:32:54 |
合計ジャッジ時間 | 5,326 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 54 WA * 2 |
ソースコード
/* -*- 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 */ ll check(int n, int x) { ll sum = 0; int a = 0, c = 0; for (int i = 0; i < n; i++) { if ((s[i] == '?' && i < x) || s[i] == 'A') a++; else sum += a, c++; } return sum; } /* main */ int main() { int n; scanf("%d%s", &n, s); int x0 = 0, x1 = n; while (x0 + 2 < x1) { int xx0 = (x0 * 2 + x1) / 3; int xx1 = (x0 + x1 * 2) / 3; ll c0 = check(n, xx0); ll c1 = check(n, xx1); if (c0 < c1) x0 = xx0; else x1 = xx1; } ll maxc = 0; for (int x = x0; x <= x1; x++) maxc = max(maxc, check(n, x)); printf("%lld\n", maxc); return 0; }