結果
問題 | No.672 最長AB列 |
ユーザー |
![]() |
提出日時 | 2018-06-08 19:14:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 9 ms / 2,000 ms |
コード長 | 457 bytes |
コンパイル時間 | 1,559 ms |
コンパイル使用メモリ | 166,480 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-30 10:41:58 |
合計ジャッジ時間 | 2,306 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main(){string s;cin >> s;int n = s.size(), puni[2 * n + 1];fill(puni, puni + 2 * n + 1, -1);int ans = 0;for (int i = 0, j = 0; i < n; i++){if (s[i] == 'A'){j++;}else{j--;}if (j == 0){ans = max(ans, i + 1);}else if (0 <= puni[n + j]){ans = max(ans, i - puni[n + j]);}else{puni[n + j] = i;}}cout << ans << endl;return 0;}