結果

問題 No.672 最長AB列
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-03-07 20:15:45
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 687 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 66,452 KB
実行使用メモリ 5,136 KB
最終ジャッジ日時 2023-09-05 19:28:17
合計ジャッジ時間 1,382 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 7 ms
5,128 KB
testcase_14 WA -
testcase_15 AC 8 ms
5,124 KB
testcase_16 AC 8 ms
5,112 KB
testcase_17 AC 7 ms
4,984 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

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