結果

問題 No.672 最長AB列
ユーザー gotutiyangotutiyan
提出日時 2018-05-06 12:49:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 844 bytes
コンパイル時間 1,577 ms
コンパイル使用メモリ 171,032 KB
実行使用メモリ 12,720 KB
最終ジャッジ日時 2023-09-10 10:43:33
合計ジャッジ時間 3,054 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
    rep(i,0,s.size()){
        if(s[i]=='A')rui++;
        else rui--;
        if(mp[rui]==0)mp[rui]=i;
        else ans=max(ans,abs(i-mp[rui]));
    }
    if(ans!=-1)cout<<ans<<endl;
    else cout<<0<<endl;
    return 0;
}
0