結果

問題 No.672 最長AB列
ユーザー 🍮かんプリン
提出日時 2019-03-07 20:15:45
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 687 bytes
コンパイル時間 603 ms
コンパイル使用メモリ 66,672 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-23 14:52:27
合計ジャッジ時間 1,289 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

    #include <iostream>
    #include <math.h>
    #include <algorithm>
    #include <vector>
    using namespace std;

    int main(){
        int c,m=0;
        string s;
        cin >> s;
        vector<int> a(2*s.length(),-1);
        a[0] = 0;
        c = 0;
        for(int i = 0; i < (int)s.length(); i++)
        {
            if (s[i] == 'A') {
                c += 1;
            }
            else {
                c -= 1;
            }
            if (a[c + s.length()] == -1) {
                a[c + s.length()] = i;
            }
            else {
                m = max(m,i - a[c + s.length()]);
            }
        }
        cout << m << endl;
        return 0;
    }
0