結果

問題 No.672 最長AB列
ユーザー rpy3cpp
提出日時 2019-05-19 23:47:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 169,420 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-17 06:36:36
合計ジャッジ時間 2,517 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int N = S.size();
    int n = N + 5;
    vector<int> pos(n * 2, -1);
    int cum = n;
    pos[cum] = 0;
    int ans = 0;
    for (int p = 0; p < N; ++p){
        if (S[p] == 'A'){
            ++cum;
        }else{
            --cum;
        }
        if (pos[cum] == -1){
            pos[cum] = p + 1;
        }else{
            ans = max(ans, p + 1 - pos[cum]);
        }
    }
    cout << ans << endl;
    return 0;
}
0