結果

問題 No.672 最長AB列
コンテスト
ユーザー くれちー
提出日時 2018-04-13 23:09:21
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 744 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 206 ms
コンパイル使用メモリ 110,080 KB
実行使用メモリ 13,088 KB
最終ジャッジ日時 2026-05-24 03:45:03
合計ジャッジ時間 4,767 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 TLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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