結果

問題 No.672 最長AB列
ユーザー kyawashellkyawashell
提出日時 2018-04-13 23:55:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,357 bytes
コンパイル時間 1,048 ms
コンパイル使用メモリ 103,168 KB
実行使用メモリ 22,120 KB
最終ジャッジ日時 2023-09-10 04:15:58
合計ジャッジ時間 2,278 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
15,204 KB
testcase_01 AC 6 ms
15,212 KB
testcase_02 AC 6 ms
15,216 KB
testcase_03 AC 6 ms
15,156 KB
testcase_04 AC 6 ms
15,360 KB
testcase_05 AC 6 ms
15,144 KB
testcase_06 AC 7 ms
15,196 KB
testcase_07 AC 7 ms
15,204 KB
testcase_08 AC 6 ms
15,112 KB
testcase_09 AC 26 ms
22,120 KB
testcase_10 AC 22 ms
18,912 KB
testcase_11 AC 22 ms
19,124 KB
testcase_12 AC 13 ms
17,072 KB
testcase_13 AC 12 ms
17,056 KB
testcase_14 AC 13 ms
17,168 KB
testcase_15 AC 13 ms
17,176 KB
testcase_16 AC 13 ms
16,984 KB
testcase_17 AC 22 ms
19,048 KB
testcase_18 AC 13 ms
16,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

string s;
int a[300000];
vector<int> c[500000];
bool used[500000];

int main(){
    cin >> s;
    ll n = s.length();
    a[0] = 0;
    REP(i,n) {
        if(s[i] == 'A') {
            a[i + 1] = 1;
        }else{
            a[i + 1] = -1;
        }
    }

    REP(i,n) {
        a[i + 1] += a[i];
    }

    REP(i,n + 1) {
        c[a[i] + n + 10].pb(i);
    }

    int maxi = -1000000000,mini = 1000000000;

    REP(i,n + 1) {
        maxi = max(maxi,a[i]);
        mini = min(mini,a[i]);
    }

    int ans = 0;
    FOR(i,mini,maxi + 1) {
        ans = max(ans,c[i + n + 10].back() - c[i + n + 10].front());
    }

    /*int ans = 0;
    REP(i,n) {
        if(!used[a[i] + n]) {
            used[a[i] + n] = true;
            ans = max(ans,c[a[i] + n][0] - i);
        }
    }*/
    cout << ans << endl;
    return 0;
}

0