結果

問題 No.672 最長AB列
ユーザー evawenisevawenis
提出日時 2020-07-05 03:45:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 546 bytes
コンパイル時間 2,221 ms
コンパイル使用メモリ 213,968 KB
実行使用メモリ 31,640 KB
最終ジャッジ日時 2023-10-21 14:14:16
合計ジャッジ時間 3,652 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 145 ms
31,640 KB
testcase_10 AC 87 ms
17,944 KB
testcase_11 AC 91 ms
17,944 KB
testcase_12 AC 23 ms
4,400 KB
testcase_13 AC 23 ms
4,400 KB
testcase_14 AC 24 ms
4,400 KB
testcase_15 AC 22 ms
4,400 KB
testcase_16 AC 22 ms
4,400 KB
testcase_17 AC 91 ms
17,944 KB
testcase_18 AC 19 ms
4,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string s; cin>>s;
	vector<int>v(s.size()+1); v.front()=0;
	unordered_map<int,int>mx,mn;
	set<int>st;
	for(int i=0;i<s.size();++i){
		v.at(i+1)=v.at(i);
		if(s.at(i)=='A')++v.at(i+1);
		else --v.at(i+1);
		mx[v.at(i+1)]=0;
		mn[v.at(i+1)]=1e9;
		st.insert(v.at(i+1));
	}
	for(int i=0;i<v.size();++i){
		mx[v.at(i)]=max(i,mx[v.at(i)]);
		mn[v.at(i)]=min(i,mn[v.at(i)]);
	}
	int ans=0;
	for(auto&&i:st)ans=max(ans,mx[i]-mn[i]);
	cout<<ans<<"\n"s;
}
0