結果

問題 No.672 最長AB列
ユーザー ahe100ahe100
提出日時 2018-06-06 17:28:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 850 bytes
コンパイル時間 568 ms
コンパイル使用メモリ 72,344 KB
実行使用メモリ 6,932 KB
最終ジャッジ日時 2023-09-12 22:45:56
合計ジャッジ時間 1,468 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 7 ms
6,588 KB
testcase_10 AC 7 ms
6,708 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 7 ms
6,696 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll mod = 1e9+7;
ll inf = 1e18;

//AC

int main(void){
	ll sum=0,last[400010],ans=0;
	string S;
	cin>>S;
	reg(i,0,2*S.size())last[i]=-2;
	last[sum+S.size()]=-1;
	rep(i,S.size()){
		if(S[i]=='A'){
			sum++;
		}else{
			sum--;
		}
		if(last[sum+S.size()]!=-2)ans=max(ans,i-last[sum+S.size()]);
		last[sum+S.size()]=i;
	}
	cout<<ans<<endl;
}
0