結果

問題 No.672 最長AB列
ユーザー mayoko_mayoko_
提出日時 2018-04-14 00:15:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 572 bytes
コンパイル時間 627 ms
コンパイル使用メモリ 66,328 KB
実行使用メモリ 5,556 KB
最終ジャッジ日時 2023-09-10 04:18:38
合計ジャッジ時間 1,669 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,068 KB
testcase_01 AC 3 ms
5,064 KB
testcase_02 AC 3 ms
5,132 KB
testcase_03 AC 3 ms
5,176 KB
testcase_04 WA -
testcase_05 AC 3 ms
5,056 KB
testcase_06 AC 3 ms
5,056 KB
testcase_07 AC 3 ms
5,208 KB
testcase_08 AC 3 ms
5,104 KB
testcase_09 AC 7 ms
5,252 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 9 ms
5,168 KB
testcase_14 WA -
testcase_15 AC 8 ms
5,252 KB
testcase_16 AC 8 ms
5,220 KB
testcase_17 AC 7 ms
5,260 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>

using namespace std;
const int MAX = 222222;
int initialPoint[MAX*2];
int* p = initialPoint + MAX;

int main() {
	string str;
	cin >> str;
	int cur = 0;
	memset(initialPoint, -1, sizeof(initialPoint));
	p[0] = 0;
	int ans = 0;
	for (int i = 0; i < str.size(); ++i) {
		const char c = str[i];
		if (c == 'A') {
			++cur;
		} else {
			--cur;
		}
		if (p[cur] < 0) {
			p[cur] = i;
		} else {
			if (!cur) ans = max(ans, cur+1);
			else ans = max(ans, i - p[cur]);
		}
	}
	cout << ans << endl;
}
0