結果

問題 No.672 最長AB列
ユーザー aim_cpoaim_cpo
提出日時 2018-04-13 23:18:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,221 bytes
コンパイル時間 1,585 ms
コンパイル使用メモリ 165,768 KB
実行使用メモリ 5,276 KB
最終ジャッジ日時 2023-09-10 00:29:02
合計ジャッジ時間 3,283 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

string s;
int n;
int acont[200001],bcont[200001];

bool check(int mid){
  if(mid&1)return 1;
  for(int i=0;i+mid<=n;i++){
    if(i==0){
      if(acont[i+mid-1]==bcont[i+mid-1])return 1;
      continue;
    }
    if(acont[i+mid]-acont[i-1]==bcont[i+mid]-bcont[i-1])return 1;
  }
  return 0;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1=freopen("in","r",stdin);
  //stream2=freopen("out","w",stdout);
  if(stream1==NULL)return 0;
  //if(stream2==NULL)return 0;
#endif
  cin>>s;
  n=(int)s.size();
  for(int i=0;i<n;i++){
    if(i==0){
      if(s[i]=='A')acont[i]=1;
      else bcont[i]=1;
    }
    if(s[i]=='A'){acont[i]=acont[i-1]+1;bcont[i]=bcont[i-1];}
    else {bcont[i]=bcont[i-1]+1;acont[i]=acont[i-1];}
  }
  int ok=0,ng=n+1;
  while(ng-ok>1){
    int mid=(ok+ng)/2;
    if(check(mid)){
      ok=mid;
    }else{
      ng=mid;
    }
  }
  if(ok&1)cout<<ok-1<<endl;
  else cout<<ok<<endl;
#ifdef LOCAL_DEFINE
  cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}
0