結果

問題 No.672 最長AB列
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-04-13 22:23:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 531 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 90,388 KB
実行使用メモリ 25,860 KB
最終ジャッジ日時 2023-09-10 00:02:24
合計ジャッジ時間 2,106 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 86 ms
25,860 KB
testcase_10 AC 59 ms
15,292 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 54 ms
15,064 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<map>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

int main(){
  string s;
  cin>>s;
  int n=s.length();
  vi acc(n+1);
  rep(i,n){
    acc[i+1]=acc[i]+(s[i]=='A'?1:-1);
  }
  int ma=0;
  map<int,vi> tt;
  rep(i,n+1){
    tt[acc[i]].push_back(i);
  }
  for(auto &e:tt){
    vi &v=e.second;
    rep(i,v.size()-1){
      ma=max(ma,v[i+1]-v[i]);
    }
  }
  cout<<ma<<endl;
}
0