結果

問題 No.672 最長AB列
ユーザー ninoinuininoinui
提出日時 2020-03-09 21:37:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 540 bytes
コンパイル時間 1,877 ms
コンパイル使用メモリ 166,892 KB
実行使用メモリ 7,680 KB
最終ジャッジ日時 2024-04-26 18:10:54
合計ジャッジ時間 2,337 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
  }
  vector<int> A(N * 2), B(N * 2);
  for (int i = 0; i < N; i++) {
    if (A.at(V.at(i) + N) == 0) A.at(V.at(i) + N) = i;
    else B.at(V.at(i) + N) = i;
  }
  int ans = 0;
  for (int i = 0; i < N * 2; i++) {
    ans = max(ans, B.at(i) - A.at(i));
  }
  cout << ans << "\n";
}
0