結果

問題 No.672 最長AB列
ユーザー null_nullnull_null
提出日時 2019-05-24 19:01:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 628 bytes
コンパイル時間 1,593 ms
コンパイル使用メモリ 175,120 KB
実行使用メモリ 43,060 KB
最終ジャッジ日時 2023-10-17 12:00:18
合計ジャッジ時間 7,453 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
30,456 KB
testcase_01 AC 126 ms
30,456 KB
testcase_02 AC 128 ms
30,456 KB
testcase_03 AC 128 ms
30,456 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 138 ms
30,484 KB
testcase_14 WA -
testcase_15 AC 140 ms
30,496 KB
testcase_16 AC 141 ms
30,496 KB
testcase_17 AC 245 ms
36,728 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 = 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]] >= 1) {
      ed[n[i]] = i;
    } else {
      st[n[i]] = i;
    }
  }

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

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