結果

問題 No.672 最長AB列
ユーザー どららどらら
提出日時 2018-04-13 22:44:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 857 bytes
コンパイル時間 1,435 ms
コンパイル使用メモリ 164,284 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-10 00:06:25
合計ジャッジ時間 2,554 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  string s;
  cin >> s;

  int lb = 0, ub = s.size()+1;
  while(ub-lb>1){
    int m = (lb+ub)/2;

    int sz = 2*m;
    
    bool flg = false;
    int A = 0;
    int B = 0;
    rep(i,min(sz,(int)s.size())){
      if(s[i] == 'A') A++;
      else B++;
    }

    if(A == m && B == m) flg = true;
    REP(i,sz,s.size()){
      if(s[i-sz] == 'A') A--;
      else B--;
      if(s[i] == 'A') A++;
      else B++;
      
      if(A == m && B == m) flg = true;
    }

    if(flg) lb = m;
    else ub = m;
  }

  cout << 2*lb << endl;
  
  return 0;
}
0