結果

問題 No.672 最長AB列
ユーザー null_nullnull_null
提出日時 2019-05-24 19:07:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 701 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 175,784 KB
実行使用メモリ 55,816 KB
最終ジャッジ日時 2023-10-17 12:00:36
合計ジャッジ時間 10,015 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 349 ms
55,764 KB
testcase_01 AC 341 ms
55,764 KB
testcase_02 AC 354 ms
55,764 KB
testcase_03 AC 339 ms
55,764 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 379 ms
55,764 KB
testcase_14 WA -
testcase_15 AC 378 ms
55,764 KB
testcase_16 AC 380 ms
55,764 KB
testcase_17 AC 445 ms
55,764 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

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