結果

問題 No.672 最長AB列
ユーザー GBGB
提出日時 2018-09-17 15:06:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 679 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 69,464 KB
実行使用メモリ 8,140 KB
最終ジャッジ日時 2023-09-25 09:23:07
合計ジャッジ時間 4,554 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>

using namespace std;

int main() {

	string str;

	cin >> str;

	int str_cout=0;
	int now=0;
	int len=0;

	if (str.size() == 1) {
		cout << len << endl;
		return 0;
	}
	else {
		for (int i = 0;i < str.size()-1;i++) {
			str_cout = 0;
			now = i;
			for (int j = i;j < str.size();j++) {
				char buf = str[j];
				if (buf == 'A')str_cout++;
				else if (buf == 'B')str_cout--;
				if (j > i && str_cout == 0) {
					int buflen = (j - now) + 1;
					if (buflen > len) {
						len = buflen;
						now = j; 
					}
				}
			}
			if (str_cout >= str.size()) {
				cout << len << endl;
				return 0;
			}
		}
	}

	cout << len << endl;

	return 0;
}
0