結果

問題 No.672 最長AB列
ユーザー dazydazy
提出日時 2018-05-03 20:09:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 507 bytes
コンパイル時間 1,301 ms
コンパイル使用メモリ 153,620 KB
実行使用メモリ 12,696 KB
最終ジャッジ日時 2023-09-10 09:22:26
合計ジャッジ時間 3,026 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 80 ms
12,696 KB
testcase_10 AC 69 ms
8,120 KB
testcase_11 AC 57 ms
8,092 KB
testcase_12 AC 13 ms
4,380 KB
testcase_13 AC 13 ms
4,380 KB
testcase_14 AC 14 ms
4,376 KB
testcase_15 AC 13 ms
4,380 KB
testcase_16 AC 13 ms
4,376 KB
testcase_17 AC 56 ms
8,004 KB
testcase_18 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define fastcin {\
    cin.tie(0);\
    ios::sync_with_stdio(false);\
}
using namespace std;

int main() {
    fastcin;
    string S;
    cin >> S;
    int l = S.length(), c = 0, ans = 0;
    map<int, int> m;
    m[0] = 0;
    for(int i = 0; i < l; i++) {
        if(S[i]=='A') c++;
        else if(S[i]=='B') c--;
        if(m.find(c)==m.end()) m[c] = i+1;
        else {
            if(ans < (i+1 - m[c])) ans = i+1 - m[c];
        }
    }
    cout << ans << "\n";
    return 0;
}
0