結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,324 KB
testcase_01 AC 5 ms
5,304 KB
testcase_02 AC 5 ms
5,576 KB
testcase_03 AC 5 ms
5,312 KB
testcase_04 WA -
testcase_05 AC 4 ms
5,264 KB
testcase_06 AC 4 ms
5,316 KB
testcase_07 AC 4 ms
5,340 KB
testcase_08 AC 4 ms
5,400 KB
testcase_09 AC 10 ms
7,084 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 10 ms
6,260 KB
testcase_14 WA -
testcase_15 AC 10 ms
6,168 KB
testcase_16 AC 10 ms
6,204 KB
testcase_17 AC 10 ms
6,728 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[s.size()] = {};
    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