結果

問題 No.672 最長AB列
ユーザー furafura
提出日時 2020-05-05 04:43:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 443 bytes
コンパイル時間 2,329 ms
コンパイル使用メモリ 197,952 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 01:43:20
合計ジャッジ時間 4,382 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	string s; cin>>s;
	int n=s.length();

	int lo=0,hi=n/2+1;
	while(hi-lo>1){
		int mi=(lo+hi)/2;
		bool ok=false;
		int a=0,b=0;
		rep(i,2*mi) (s[i]=='A'?a:b)++;
		for(int i=2*mi;i<=n;i++){
			if(a==b) ok=true;
			if(i<n) (s[i]=='A'?a:b)++;
			(s[i-2*mi]=='A'?a:b)--;
		}
		if(ok) lo=mi;
		else   hi=mi;
	}
	printf("%d\n",2*lo);

	return 0;
}
0