結果

問題 No.672 最長AB列
ユーザー DaYuanChiDaYuanChi
提出日時 2021-01-27 00:57:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 558 bytes
コンパイル時間 4,204 ms
コンパイル使用メモリ 170,764 KB
実行使用メモリ 15,124 KB
最終ジャッジ日時 2023-09-06 03:58:46
合計ジャッジ時間 3,190 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 85 ms
15,124 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 16 ms
5,824 KB
testcase_14 WA -
testcase_15 AC 16 ms
5,844 KB
testcase_16 AC 17 ms
5,848 KB
testcase_17 AC 62 ms
10,460 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int a[200005];
int b[200005];
int c[200005];
map<int,int> mp;

int main(){
  string s;
  cin >> s;
  int n = s.size();
  for(int i = 1; i <= n; i++){
    if(s[i-1]=='A'){
      a[i] = a[i-1]+1;
      b[i] = b[i-1];
    }else{
      a[i] = a[i-1];
      b[i] = b[i-1]+1;
    }
  }
  int ans = 0;
  for(int i = 1; i <= n; i++) c[i] = a[i]-b[i];
  for(int i = 1; i <= n; i++){
    if(mp[c[i]]==0) mp[c[i]] = i;
    else ans = max(ans, i-mp[c[i]]);
  }
  cout << ans << endl;    
  return 0;
}
0