結果

問題 No.672 最長AB列
ユーザー 0w10w1
提出日時 2018-04-13 22:33:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 712 bytes
コンパイル時間 2,596 ms
コンパイル使用メモリ 209,312 KB
実行使用メモリ 23,636 KB
最終ジャッジ日時 2023-09-10 00:03:41
合計ジャッジ時間 4,248 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 240 ms
23,636 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 18 ms
5,012 KB
testcase_14 WA -
testcase_15 AC 18 ms
5,080 KB
testcase_16 AC 18 ms
5,152 KB
testcase_17 AC 166 ms
14,408 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

signed main() {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  vector<int> pa(S.size() + 1), pb(S.size() + 1);
  map<int, int> minpos, maxpos;
  minpos[0] = maxpos[0] = 0;
  for (int i = 0; i < S.size(); ++i) {
    pa[i + 1] = pa[i] + (S[i] == 'A');
    pb[i + 1] = pb[i] + (S[i] == 'B');
    int d = pa[i + 1] - pb[i + 1];
    if (minpos.count(d)) minpos[d] = min(minpos[d], i);
    else minpos[d] = i;
    maxpos[d] = max(maxpos[d], i);
  }
  int ans = 0;
  for (auto it = minpos.begin(); it != minpos.end(); ++it) {
    if (maxpos.count(it->first)) {
      ans = max(ans, maxpos[it->first] - it->second);
    }
  }
  cout << ans << endl;
  return 0;
}
0