結果
問題 |
No.672 最長AB列
|
ユーザー |
![]() |
提出日時 | 2020-03-09 21:28:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 615 bytes |
コンパイル時間 | 1,528 ms |
コンパイル使用メモリ | 169,720 KB |
実行使用メモリ | 17,992 KB |
最終ジャッジ日時 | 2024-11-14 07:52:25 |
合計ジャッジ時間 | 32,391 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 TLE * 10 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int N = S.size() + 1; vector<int> V(N); for (int i = 0, cnt = 0; i < S.size(); i++) { if (S.at(i) == 'A') cnt++, V.at(i + 1) = cnt; else cnt--, V.at(i + 1) = cnt; } int ans = 0; for (int i = 0; i < N; i++) { if (i < N / 2) { for (int j = i - 1; j >= 0; j--) { if (V.at(j) == V.at(i + i - j)) ans = max(ans, (i - j) * 2); } } else { for (int j = i + 1; j < N; j++) { if (V.at(j) == V.at(i + i - j)) ans = max(ans, (j - i) * 2); } } } cout << ans << "\n"; }