結果

問題 No.672 最長AB列
ユーザー autumn-eel
提出日時 2018-05-26 20:56:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 461 bytes
コンパイル時間 1,420 ms
コンパイル使用メモリ 175,292 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2024-06-28 18:16:42
合計ジャッジ時間 2,467 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	string s;cin>>s;
	map<int,int>mp;
	int a=0,b=0;
	mp[a-b]=-1;
	int ans=0;
	rep(i,s.size()){
		if(s[i]=='A')a++;
		else b++;
		if(mp.count(a-b)){
			ans=max(ans,i-mp[a-b]);
		}
		else mp[a-b]=i;
	}
	cout<<ans<<endl;
}
0