結果

問題 No.672 最長AB列
ユーザー ts_ts_
提出日時 2018-04-15 05:37:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 609 bytes
コンパイル時間 1,651 ms
コンパイル使用メモリ 144,840 KB
実行使用メモリ 6,876 KB
最終ジャッジ日時 2023-09-10 04:29:48
合計ジャッジ時間 2,745 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,464 KB
testcase_01 AC 5 ms
6,492 KB
testcase_02 AC 4 ms
6,480 KB
testcase_03 AC 4 ms
6,528 KB
testcase_04 AC 4 ms
6,472 KB
testcase_05 AC 4 ms
6,540 KB
testcase_06 AC 5 ms
6,776 KB
testcase_07 AC 5 ms
6,488 KB
testcase_08 AC 4 ms
6,600 KB
testcase_09 AC 9 ms
6,720 KB
testcase_10 AC 9 ms
6,620 KB
testcase_11 AC 8 ms
6,608 KB
testcase_12 AC 10 ms
6,876 KB
testcase_13 AC 9 ms
6,876 KB
testcase_14 AC 10 ms
6,720 KB
testcase_15 AC 10 ms
6,600 KB
testcase_16 AC 10 ms
6,652 KB
testcase_17 AC 9 ms
6,612 KB
testcase_18 AC 9 ms
6,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

pint a[410001];
int main(){
    string s;
    cin>>s;
    int n=s.size();
    int cur=200000;
    rep(i,400001) a[i]={-1,-1};
    a[cur].first=0;
    rep(i,n){
        if(s[i]=='A') ++cur;
        else --cur;
        if(a[cur].first==-1) a[cur].first=i+1;
        else a[cur].second=i+1;
    }
    int mx=0;
    rep(i,400001)if(a[i].second!=-1)mx=max(mx,a[i].second-a[i].first);
    cout<<mx<<endl;
    return 0;
}
0