結果

問題 No.672 最長AB列
ユーザー null_null
提出日時 2019-05-24 19:12:59
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 399 bytes
コンパイル時間 1,699 ms
コンパイル使用メモリ 175,948 KB
実行使用メモリ 16,000 KB
最終ジャッジ日時 2024-09-17 10:12:07
合計ジャッジ時間 2,580 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
  string s;
  cin >> s;

  int N = s.size();
  map<int, int> m;
  int p = 0;
  m[0] = -1;

  int ans = 0;
  for (int i = 0; i < N; i++) {
    char c = s[i];
    if (c == 'A')
      p++;
    else
      p--;

    if (m[p]) ans = max(ans, i - m[p]);
    if (!m[p]) m[p] = i;
  }

  cout << ans << endl;
  return 0;
}
0