結果

問題 No.672 最長AB列
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-03-07 22:00:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 575 bytes
コンパイル時間 550 ms
コンパイル使用メモリ 66,136 KB
実行使用メモリ 5,136 KB
最終ジャッジ日時 2023-09-05 19:28:29
合計ジャッジ時間 1,351 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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,-2);
    a[s.length()] = -1;
    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()] == -2) {
            a[c + s.length()] = i;
        }
        else {
            m = max(m,i - a[c + s.length()]);
        }
    }
    cout << m << endl;
    return 0;
}
0