結果

問題 No.672 最長AB列
ユーザー ninoinuininoinui
提出日時 2020-03-09 21:28:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 615 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 165,420 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2024-04-26 18:02:43
合計ジャッジ時間 5,239 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
9,728 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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";
}
0