結果

問題 No.1433 Two color sequence
ユーザー kokatsukokatsu
提出日時 2021-11-18 20:58:31
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 579 bytes
コンパイル時間 2,117 ms
コンパイル使用メモリ 204,224 KB
実行使用メモリ 17,684 KB
最終ジャッジ日時 2023-09-04 14:59:47
合計ジャッジ時間 5,488 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 22 ms
12,968 KB
testcase_04 AC 22 ms
12,956 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 49 ms
16,756 KB
testcase_09 AC 48 ms
16,880 KB
testcase_10 AC 45 ms
15,580 KB
testcase_11 AC 46 ms
16,120 KB
testcase_12 AC 47 ms
16,960 KB
testcase_13 AC 48 ms
16,920 KB
testcase_14 AC 48 ms
17,512 KB
testcase_15 AC 47 ms
16,864 KB
testcase_16 AC 48 ms
17,116 KB
testcase_17 AC 47 ms
16,880 KB
testcase_18 AC 47 ms
16,972 KB
testcase_19 AC 47 ms
16,900 KB
testcase_20 AC 47 ms
17,684 KB
testcase_21 AC 47 ms
17,024 KB
testcase_22 AC 47 ms
16,824 KB
testcase_23 AC 47 ms
17,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    int N;
    readf("%d\n", N);

    string S = readln.chomp;

    auto a = readln.chomp.split.to!(long[]);

    long amax, amin;

    auto dpmax = new long[](N+1), dpmin = new long[](N+1);
    dpmax[0] = long.min / 2, dpmin[0] = long.max / 2;
    foreach (i, s; S) {
        if (s == 'B') {
            a[i] *= -1;
        }

        amax = max(amax+a[i], a[i]), amin = min(amin+a[i], a[i]);

        dpmax[i+1] = max(dpmax[i], amax);
        dpmin[i+1] = min(dpmin[i], amin);
    }

    long res = max(dpmax[N].abs, dpmin[N].abs);
    res.writeln;
}
0