結果
問題 | No.672 最長AB列 |
ユーザー |
|
提出日時 | 2024-12-24 23:56:50 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 753 bytes |
コンパイル時間 | 775 ms |
コンパイル使用メモリ | 77,244 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-24 23:57:05 |
合計ジャッジ時間 | 1,525 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include <iostream> #include <cstdint> using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); static char S[200001]; cin >> S; static uint32_t first_index[400001], ans = 0, count_A = 0, count_B = 0, i; for (i = 0; i <= 400000; ++i) first_index[i] = UINT32_MAX; first_index[200000] = 0; for (i = 0; ; ++i) { switch (S[i]) { case 'A': ++count_A; break; case 'B': ++count_B; break; case '\0': cout << ans << '\n'; return 0; } if (first_index[200000 + count_A - count_B] == UINT32_MAX) first_index[200000 + count_A - count_B] = i + 1; else if (ans < i + 1 - first_index[200000 + count_A - count_B]) ans = i + 1 - first_index[200000 + count_A - count_B]; } return -1; }