結果

問題 No.672 最長AB列
ユーザー くれちーくれちー
提出日時 2018-04-13 23:09:21
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 744 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 68,876 KB
実行使用メモリ 11,428 KB
最終ジャッジ日時 2023-08-20 10:38:18
合計ジャッジ時間 5,058 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,084 KB
testcase_01 AC 3 ms
4,600 KB
testcase_02 AC 3 ms
4,624 KB
testcase_03 AC 2 ms
4,592 KB
testcase_04 AC 3 ms
4,692 KB
testcase_05 AC 3 ms
4,692 KB
testcase_06 AC 3 ms
4,604 KB
testcase_07 AC 3 ms
4,620 KB
testcase_08 AC 3 ms
4,592 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string.h>
#define S_MAX 200001

int main() {
    char s[S_MAX];
    scanf("%s", s);
    int len = strlen(s);

    int a[S_MAX] = { 0 }, b[S_MAX] = { 0 };
    for (int i = len - 1; i >= 0; --i) {
        if (s[i] == 'A') ++a[i];
        else if (s[i] == 'B') ++b[i];
        a[i] += a[i + 1];
        b[i] += b[i + 1];
    }

    int ans = 0;
    for (int i = 0; i < len - 1; ++i) {
        int cnt = b[i] - a[i];
        for (int j = len - 1; j >= i; --j) {
            if (cnt == 0) {
                if (j - i + 1 > ans) ans = j - i + 1;
                break;
            }
            if (s[j] == 'A') ++cnt;
            else if (s[j] == 'B') --cnt;
        }
    }
    
    printf("%d\n", ans);
    return 0;
}
0