結果

問題 No.818 Dinner time
ユーザー nebukuro09nebukuro09
提出日時 2019-04-19 22:01:16
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 1,065 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 108,096 KB
実行使用メモリ 14,932 KB
最終ジャッジ日時 2023-09-04 00:41:32
合計ジャッジ時間 4,225 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 87 ms
14,000 KB
testcase_18 AC 57 ms
14,384 KB
testcase_19 AC 60 ms
13,044 KB
testcase_20 AC 80 ms
13,672 KB
testcase_21 AC 71 ms
14,932 KB
testcase_22 AC 56 ms
12,632 KB
testcase_23 AC 65 ms
14,040 KB
testcase_24 AC 94 ms
13,896 KB
testcase_25 AC 65 ms
13,856 KB
testcase_26 AC 56 ms
13,116 KB
testcase_27 AC 83 ms
14,040 KB
testcase_28 AC 69 ms
13,964 KB
testcase_29 AC 89 ms
13,820 KB
testcase_30 AC 77 ms
14,088 KB
testcase_31 AC 83 ms
14,168 KB
testcase_32 AC 67 ms
13,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto AB = N.iota.map!(_ => readln.split.map!(to!long).array).array;

    auto dp = new long[][](N+1, 2);
    foreach (i; 0..N+1) dp[i][] = - (1L << 59);
    dp[0][0] = 0;

    foreach (i; 0..N) {
        long tmp = 0;
        long a = AB[i][0], b = AB[i][1];

        if (a >= 0 && b >= 0) {
            tmp += a * (M - 1) + max(a, b);          
        } else if (a < 0 && b >= 0) {
            tmp += b;
        } else if (a >= 0 && b < 0) {
            tmp += a * M;
        } else {
            tmp += max(a * M, b);
        }

        dp[i+1][0] = max(dp[i+1][0], dp[i][0] + tmp);
        dp[i+1][1] = max(dp[i+1][1], dp[i][0] + max(a, b));
        dp[i+1][1] = max(dp[i+1][1], dp[i][1] + max(a, b));
    }

    dp[1..$].map!(d => d.reduce!max).reduce!max.writeln;
}
0