結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,008 KB
testcase_01 AC 3 ms
4,916 KB
testcase_02 AC 3 ms
4,968 KB
testcase_03 AC 3 ms
4,888 KB
testcase_04 AC 3 ms
4,968 KB
testcase_05 AC 2 ms
4,920 KB
testcase_06 AC 3 ms
4,872 KB
testcase_07 AC 3 ms
4,968 KB
testcase_08 AC 3 ms
4,948 KB
testcase_09 AC 11 ms
8,260 KB
testcase_10 AC 10 ms
7,392 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 9 ms
6,664 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(ll 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----------

ll a[200030];
ll mx[200030];
ll mn[200030];
ll 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