結果

問題 No.672 最長AB列
ユーザー beetbeet
提出日時 2018-07-26 13:35:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 504 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 172,932 KB
実行使用メモリ 15,916 KB
最終ジャッジ日時 2023-09-13 18:38:58
合計ジャッジ時間 3,693 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 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,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 134 ms
15,916 KB
testcase_10 AC 92 ms
9,664 KB
testcase_11 AC 86 ms
9,720 KB
testcase_12 AC 15 ms
4,376 KB
testcase_13 AC 15 ms
4,380 KB
testcase_14 AC 14 ms
4,376 KB
testcase_15 AC 15 ms
4,380 KB
testcase_16 AC 14 ms
4,376 KB
testcase_17 AC 87 ms
9,664 KB
testcase_18 AC 7 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  Int n=s.size();
  Int ans=0;
  map<Int, Int> m;
  m[0]=-1;
  Int k=0;
  for(Int i=0;i<n;i++){
    if(s[i]=='A') k++;
    else k--;
    if(!m.count(k)) m[k]=i;
    chmax(ans,i-m[k]);
  }
  cout<<ans<<endl;
  return 0;
}
0