結果

問題 No.672 最長AB列
ユーザー gotutiyangotutiyan
提出日時 2018-05-06 19:57:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 997 bytes
コンパイル時間 1,649 ms
コンパイル使用メモリ 173,612 KB
実行使用メモリ 12,836 KB
最終ジャッジ日時 2023-09-10 10:48:38
合計ジャッジ時間 2,894 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 87 ms
12,836 KB
testcase_10 AC 63 ms
8,024 KB
testcase_11 AC 57 ms
7,996 KB
testcase_12 AC 13 ms
4,380 KB
testcase_13 AC 13 ms
4,376 KB
testcase_14 AC 13 ms
4,376 KB
testcase_15 AC 13 ms
4,376 KB
testcase_16 AC 14 ms
4,376 KB
testcase_17 AC 62 ms
7,988 KB
testcase_18 AC 6 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    string s;
    map<int,int> mp;
    cin>>s;
    int rui=0;
    int ans=-1;
    mp[0]=0;
    rep(i,0,s.size()){
        if(s[i]=='A')rui++;
        else rui--;
        if(rui==0){
            ans=max(ans,i+1);
            continue;
        }
        if(mp[rui]==0)mp[rui]=i+1;
        else ans=max(ans,abs(i-mp[rui]+1));
        //cout<<rui<<endl;
        //cout<<rui<<endl;
    }
    if(ans!=-1)cout<<ans<<endl;
    else cout<<0<<endl;
    return 0;
}
0