結果

問題 No.672 最長AB列
ユーザー silopysilopy
提出日時 2019-01-26 15:40:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 504 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 62,352 KB
実行使用メモリ 5,180 KB
最終ジャッジ日時 2023-10-14 10:14:39
合計ジャッジ時間 1,464 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
	string S;
	
	cin >> S;
	
	int ans=0;
	int a[200010]={};
	int b[200010]={};
	int acnt=0;
	
	if(S[0]=='A')a[0]=1;
	if(S[0]=='B')b[0]=1;
	for(int i=1;i<S.size();i++)
	{
		//a
		a[i]=a[i-1];
		if(S[i]=='A')
		{
			if(S[i-1]=='A')a[i]++;
			else a[i]=1;
		}
		//b
		b[i]=b[i-1];
		if(S[i]=='B')
		{
			if(S[i-1]=='B')b[i]++;
			else b[i]=1;
		}
		ans=max(ans,min(a[i],b[i]	));
	}
	
	cout << ans*2 << endl;
	return 0;
}
0