結果

問題 No.672 最長AB列
コンテスト
ユーザー autumn-eel
提出日時 2018-05-26 20:56:10
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 461 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 997 ms
コンパイル使用メモリ 192,488 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2026-03-17 18:32:46
合計ジャッジ時間 2,070 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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