結果

問題 No.672 最長AB列
ユーザー focus
提出日時 2018-05-22 15:14:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 384 bytes
コンパイル時間 732 ms
コンパイル使用メモリ 83,800 KB
実行使用メモリ 16,000 KB
最終ジャッジ日時 2024-06-28 15:45:35
合計ジャッジ時間 1,798 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
using ll = long long ;
using namespace std;
int main(){
	string str;
	map<ll,ll> m;
	m[0] = 0;
	ll ans=0,p=0;
	cin >> str;
	ll len = str.size();
	for(ll i=1;i<=len;i++){
		if(str[i-1]=='A')	p++;
		else	p--;
		if(m.count(p)) ans=max(ans,i-m[p]);
		else m[p]=i;
	}
	cout << ans << endl;
	return 0;
}
0