結果

問題 No.672 最長AB列
ユーザー evawenisevawenis
提出日時 2020-07-05 03:44:53
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 546 bytes
コンパイル時間 2,269 ms
コンパイル使用メモリ 213,872 KB
実行使用メモリ 31,648 KB
最終ジャッジ日時 2023-10-21 14:12:49
合計ジャッジ時間 5,022 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,348 KB
testcase_04 WA -
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 129 ms
31,648 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 22 ms
4,408 KB
testcase_14 WA -
testcase_15 AC 21 ms
4,408 KB
testcase_16 AC 21 ms
4,408 KB
testcase_17 AC 78 ms
17,952 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

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=1;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