結果

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

ソースコード

diff #

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

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

  static int n[202020];
  memset(n, 0, sizeof(n));

  map<int, int> st, ed;
  for (int i = -202020; i <= 202020; i++) st[i] = ed[i] = 1e18;

  for (int i = 1; i <= s.size(); i++) {
    if (s[i] == 'A') {
      n[i] = n[i - 1] + 1;
    } else {
      n[i] = n[i - 1] - 1;
    }
  }

  for (int i = 1; i <= s.size(); i++) {
    if (st[n[i]] != 1e18) {
      ed[n[i]] = i;
    } else {
      st[n[i]] = i;
    }
  }

  int ans = 0;
  for (int i = -202020; i <= 202020; i++) {
    if (st[i] != 1e18 && ed[i] != 1e18) ans = max(ans, abs(st[i] - ed[i]));
  }

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