結果

問題 No.672 最長AB列
ユーザー a0171610a0171610
提出日時 2020-05-20 15:39:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 667 bytes
コンパイル時間 1,426 ms
コンパイル使用メモリ 165,148 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-04-09 22:58:24
合計ジャッジ時間 5,108 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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());
	int ans = 0;
	for(int i = 0; i <= lim; i++){
		int a = 0, b = 0;
		rep(j, n){
			if(data[j] == i){
				a = j;
				break;
			}
		}
		for(int j = n - 1; j >= 0; j--){
			if(data[j] == i){
				b = j;
				break;
			}
		}
		ans = max(ans, b - a);
	}
	cout << ans << endl;
}
0