結果

問題 No.672 最長AB列
ユーザー ohreitetsuohreitetsu
提出日時 2018-04-22 12:52:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 796 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 66,380 KB
実行使用メモリ 8,888 KB
最終ジャッジ日時 2023-09-10 04:46:48
合計ジャッジ時間 4,542 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string> 
using namespace std;
int getMaxLen(string S)
{
	int i;
	int maxLen=0;
	string maxString;
	int aNum=0,bNum=0;
	int len=1;
	for (i=0;i<S.size();i++){
		if (S[i]=='A'){
			aNum++;
		}else{
			bNum++;
		}
		if (aNum==bNum){
			if (maxLen<i+1){
				maxLen=i+1;
			}
		}
	}
	return maxLen;	
}
int main(int argc, char* argv[])
{
	string S;
	cin>>S;
	int len=S.size();
	int aNum=0,bNum=0;
	int i=0;
	for (i=0;i<len;i++){
		if (S[i]=='A'){
			aNum++;
		}else{
			bNum++;
		}
	}
	if (aNum==0 || bNum==0){
		cout<<0<<endl;
		return 0;
	}else if (aNum==bNum){
		cout<<len<<endl;
		return 0;
	}
	int MaxLen=0;
	char *p=(char*)S.c_str();
	while (*p!='\0'){
		int maxLen=getMaxLen(p);
		if (maxLen>MaxLen){
			MaxLen=maxLen;
		}
		p++;
	}
	cout<<MaxLen<<endl;
	return 0;
}
0