結果

問題 No.672 最長AB列
ユーザー gotutiyangotutiyan
提出日時 2018-05-06 19:56:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 995 bytes
コンパイル時間 1,542 ms
コンパイル使用メモリ 175,812 KB
実行使用メモリ 12,856 KB
最終ジャッジ日時 2023-09-10 10:48:34
合計ジャッジ時間 5,985 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
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;
    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