結果

問題 No.672 最長AB列
ユーザー mayoko_mayoko_
提出日時 2018-04-14 00:23:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 535 bytes
コンパイル時間 548 ms
コンパイル使用メモリ 67,312 KB
実行使用メモリ 5,256 KB
最終ジャッジ日時 2023-09-10 04:18:42
合計ジャッジ時間 1,637 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,024 KB
testcase_01 AC 3 ms
5,108 KB
testcase_02 AC 3 ms
4,968 KB
testcase_03 AC 3 ms
5,040 KB
testcase_04 AC 3 ms
5,056 KB
testcase_05 AC 3 ms
5,096 KB
testcase_06 AC 3 ms
5,168 KB
testcase_07 AC 3 ms
5,040 KB
testcase_08 AC 3 ms
5,068 KB
testcase_09 AC 7 ms
5,168 KB
testcase_10 AC 7 ms
5,164 KB
testcase_11 AC 7 ms
5,096 KB
testcase_12 AC 8 ms
5,168 KB
testcase_13 AC 8 ms
5,168 KB
testcase_14 AC 8 ms
5,120 KB
testcase_15 AC 8 ms
5,256 KB
testcase_16 AC 8 ms
5,100 KB
testcase_17 AC 7 ms
5,220 KB
testcase_18 AC 7 ms
5,252 KB
権限があれば一括ダウンロードができます

ソースコード

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+1;
		} else {
			ans = max(ans, i+1 - p[cur]);
		}
	}
	cout << ans << endl;
}
0