結果

問題 No.672 最長AB列
ユーザー kyawashellkyawashell
提出日時 2018-04-13 23:43:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,078 bytes
コンパイル時間 1,020 ms
コンパイル使用メモリ 105,144 KB
実行使用メモリ 443,312 KB
最終ジャッジ日時 2023-09-10 04:11:43
合計ジャッジ時間 8,391 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 283 ms
339,196 KB
testcase_01 AC 276 ms
339,312 KB
testcase_02 AC 275 ms
339,248 KB
testcase_03 AC 279 ms
339,408 KB
testcase_04 WA -
testcase_05 AC 274 ms
339,384 KB
testcase_06 AC 275 ms
339,248 KB
testcase_07 AC 275 ms
339,312 KB
testcase_08 AC 279 ms
339,336 KB
testcase_09 AC 443 ms
443,312 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 312 ms
341,096 KB
testcase_14 WA -
testcase_15 AC 314 ms
341,136 KB
testcase_16 AC 312 ms
341,128 KB
testcase_17 AC 376 ms
391,712 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

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];
deque<int> c[500000];
bool used[500000];

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

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

    REP(i,n) {
        c[a[i] + n].push_front(i);
    }

    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