結果

問題 No.672 最長AB列
ユーザー ninoinui
提出日時 2020-03-09 21:37:26
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 540 bytes
コンパイル時間 1,581 ms
コンパイル使用メモリ 170,904 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-11-14 08:03:27
合計ジャッジ時間 2,412 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 6
権限があれば一括ダウンロードができます

ソースコード

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