結果

問題 No.818 Dinner time
ユーザー nebukuro09nebukuro09
提出日時 2019-04-19 22:09:05
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,136 bytes
コンパイル時間 762 ms
コンパイル使用メモリ 108,372 KB
実行使用メモリ 14,540 KB
最終ジャッジ日時 2023-09-04 00:41:46
合計ジャッジ時間 3,770 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 90 ms
13,924 KB
testcase_18 AC 59 ms
12,812 KB
testcase_19 AC 63 ms
14,104 KB
testcase_20 AC 85 ms
13,992 KB
testcase_21 AC 73 ms
13,704 KB
testcase_22 AC 57 ms
12,664 KB
testcase_23 AC 65 ms
13,608 KB
testcase_24 AC 95 ms
14,512 KB
testcase_25 AC 65 ms
13,960 KB
testcase_26 AC 55 ms
13,124 KB
testcase_27 AC 85 ms
13,960 KB
testcase_28 AC 68 ms
14,540 KB
testcase_29 AC 90 ms
14,440 KB
testcase_30 AC 79 ms
13,388 KB
testcase_31 AC 84 ms
14,024 KB
testcase_32 AC 67 ms
13,924 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].to!long;
    auto AB = N.iota.map!(_ => readln.split.map!(to!long).array).array;

    long calc(int i) {
        long a = AB[i][0], b = AB[i][1];
        if (a >= 0 && b >= 0) {
            return a * (M - 1) + max(a, b);          
        } else if (a < 0 && b >= 0) {
            return b;
        } else if (a >= 0 && b < 0) {
            return a * M;
        } else {
            return max(a * M, b);
        }
    }

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

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

        dp[i+1][0] = max(dp[i+1][0], dp[i][0] + calc(i+1));
        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.map!(d => d.reduce!max).reduce!max.writeln;
}
0