結果

問題 No.672 最長AB列
ユーザー a0171610a0171610
提出日時 2020-05-20 15:45:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 586 bytes
コンパイル時間 1,601 ms
コンパイル使用メモリ 166,804 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 22:58:28
合計ジャッジ時間 3,851 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define REP(a, b, n) for(int i = a; i < b; i++)
using lint = long long;

signed main(){
	string s; cin >> s;
	int n = s.size();
	vector<int> data(n + 1, 0);
	rep(i, n){
		if(s[i] == 'A') data[i + 1] = data[i] + 1;
		else data[i + 1] = data[i] - 1;
	}
	int lim = *max_element(data.begin(), data.end());
	vector<int> memo(lim + 1, 0);
	int ans = 0;
	for(int i = 0; i <= n; i++){
		int x = data[i];
		if(memo[x] == 0) memo[x] = i;
		else ans = max(ans, i - memo[x]);
	}
	cout << ans << endl;
}
0