結果

問題 No.672 最長AB列
ユーザー simauma1203simauma1203
提出日時 2018-04-21 12:55:23
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,031 bytes
コンパイル時間 570 ms
コンパイル使用メモリ 63,628 KB
実行使用メモリ 5,852 KB
最終ジャッジ日時 2023-09-10 04:45:08
合計ジャッジ時間 2,745 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define INF 93193111451418101
#define MIN -93193111451418101
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//----------program from here----------

int a[200030];
int mx[200030];
int mn[200030];
int ans;
int main(){
    string s;
    
    REP(i,200020){
      mn[i]=1145141919;
    }
    mn[0]=0;


    cin>>s;
    REP(i,s.length()){
      if(s[i]=='A'){a[i+1]=a[i]+1;}
      else {a[i+1]=a[i]-1;}
    }
    REP(i,s.length()+1){
      //cout<<a[i]<<endl;
      mx[a[i]]=max(i,mx[a[i]]);
      mn[a[i]]=min(i,mn[a[i]]);
    }
    REP(i,s.length()+1){
      //cout<<mx[i]<<" "<<mn[i]<<endl;
      ans=max(mx[i]-mn[i],ans);
    }

    cout<<ans<<endl;



    return 0;
}
0