結果

問題 No.672 最長AB列
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-04-13 22:25:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 507 bytes
コンパイル時間 876 ms
コンパイル使用メモリ 90,312 KB
実行使用メモリ 25,832 KB
最終ジャッジ日時 2023-09-10 00:02:45
合計ジャッジ時間 2,094 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 87 ms
25,832 KB
testcase_10 AC 61 ms
15,080 KB
testcase_11 AC 59 ms
15,192 KB
testcase_12 AC 13 ms
5,192 KB
testcase_13 AC 13 ms
5,624 KB
testcase_14 AC 14 ms
5,304 KB
testcase_15 AC 13 ms
5,524 KB
testcase_16 AC 13 ms
5,192 KB
testcase_17 AC 57 ms
15,096 KB
testcase_18 AC 8 ms
5,124 KB
権限があれば一括ダウンロードができます

ソースコード

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;
    ma=max(ma,v[v.size()-1]-v[0]);
  }
  cout<<ma<<endl;
}
0