結果

問題 No.672 最長AB列
ユーザー ilplrrilplrr
提出日時 2018-04-13 23:17:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 610 bytes
コンパイル時間 1,258 ms
コンパイル使用メモリ 144,404 KB
実行使用メモリ 7,228 KB
最終ジャッジ日時 2023-09-10 00:28:57
合計ジャッジ時間 2,229 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,068 KB
testcase_01 AC 5 ms
6,068 KB
testcase_02 AC 5 ms
6,188 KB
testcase_03 AC 5 ms
6,072 KB
testcase_04 WA -
testcase_05 AC 4 ms
6,068 KB
testcase_06 AC 5 ms
6,084 KB
testcase_07 AC 5 ms
6,316 KB
testcase_08 AC 5 ms
6,164 KB
testcase_09 AC 10 ms
7,228 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 11 ms
6,336 KB
testcase_14 WA -
testcase_15 AC 10 ms
6,228 KB
testcase_16 AC 10 ms
6,172 KB
testcase_17 AC 9 ms
6,712 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int mi[500010];
int ma[500010];

int main()
{
    string s;
    cin >> s;

    int a[200010] = {};
    for (int& x : mi) x = 1 << 29;

    for (int i = 0; i < s.size(); i++) {
        if (i) a[i] = a[i -  1];
        if (s[i] == 'A') a[i]++;
        else a[i]--;
        mi[a[i] + 200010] = min(mi[a[i] + 200010], i);
        ma[a[i] + 200010] = max(ma[a[i] + 200010], i);
    }

    int ans = 0;
    for (int i = 0; i < 500010; i++) {
        if (ma[i] == 1 << 29) continue;
        ans = max(ans, ma[i] - mi[i]);
    }
    cout << ans << endl;

    return 0;
}
0