結果

問題 No.672 最長AB列
ユーザー first_vilfirst_vil
提出日時 2021-11-17 13:50:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 336 bytes
コンパイル時間 2,155 ms
コンパイル使用メモリ 207,468 KB
実行使用メモリ 12,808 KB
最終ジャッジ日時 2023-08-25 01:13:15
合計ジャッジ時間 3,353 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 85 ms
12,808 KB
testcase_10 AC 63 ms
8,056 KB
testcase_11 AC 57 ms
8,036 KB
testcase_12 AC 13 ms
4,380 KB
testcase_13 AC 13 ms
4,380 KB
testcase_14 AC 14 ms
4,380 KB
testcase_15 AC 13 ms
4,380 KB
testcase_16 AC 13 ms
4,376 KB
testcase_17 AC 60 ms
8,112 KB
testcase_18 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
int main() {
	string s; cin >> s;
	int n = s.size();
	int a = 0, ans = 0;
	map<int, int> mp;
	mp[0] = -1;
	rep(i,n) {
		a += s[i] == 'A' ? 1 : -1;
		if (mp.count(a))ans = max(ans, i - mp[a]);
		else mp[a] = i;
	}
	cout << ans << "\n";
	
	return 0;
}
0