結果

問題 No.672 最長AB列
ユーザー sggkshiosggkshio
提出日時 2019-10-03 07:53:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 732 bytes
コンパイル時間 1,333 ms
コンパイル使用メモリ 92,032 KB
実行使用メモリ 24,448 KB
最終ジャッジ日時 2024-04-14 09:03:57
合計ジャッジ時間 5,268 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
24,192 KB
testcase_01 AC 126 ms
24,192 KB
testcase_02 AC 126 ms
24,192 KB
testcase_03 AC 124 ms
24,320 KB
testcase_04 AC 124 ms
24,192 KB
testcase_05 AC 124 ms
24,192 KB
testcase_06 AC 124 ms
24,320 KB
testcase_07 AC 123 ms
24,320 KB
testcase_08 AC 125 ms
24,192 KB
testcase_09 AC 193 ms
24,448 KB
testcase_10 AC 189 ms
24,448 KB
testcase_11 AC 186 ms
24,448 KB
testcase_12 AC 165 ms
24,320 KB
testcase_13 AC 165 ms
24,448 KB
testcase_14 AC 165 ms
24,448 KB
testcase_15 AC 166 ms
24,448 KB
testcase_16 AC 166 ms
24,448 KB
testcase_17 AC 189 ms
24,448 KB
testcase_18 AC 154 ms
24,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {


	string p;
	cin >> p;
	int ans = 0;

	map<int, int>t;
	for (int i = -222222; i <= 222222; i++) {
		t[i] = -1;
	}
//	t[0] = 0;
	int a = 0;
	for (int i = 0; i < p.size(); i++) {
		if (p[i] == 'A')a++;
		else a--;
		if (a&&t[a] == -1)t[a] = i;
		else {
			ans = max(ans, i - t[a]);
		}
	//	cout << ans << endl;
	}


	cout << ans << endl;


	return 0;




}
0