結果

問題 No.489 株に挑戦
ユーザー nebukuro09nebukuro09
提出日時 2017-02-25 00:12:12
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 91 ms / 1,000 ms
コード長 2,238 bytes
コンパイル時間 813 ms
コンパイル使用メモリ 105,784 KB
実行使用メモリ 6,428 KB
最終ジャッジ日時 2023-09-03 01:36:27
合計ジャッジ時間 4,755 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
6,184 KB
testcase_01 AC 44 ms
4,688 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 79 ms
5,888 KB
testcase_17 AC 10 ms
4,380 KB
testcase_18 AC 44 ms
4,616 KB
testcase_19 AC 35 ms
4,508 KB
testcase_20 AC 81 ms
6,428 KB
testcase_21 AC 19 ms
4,380 KB
testcase_22 AC 8 ms
4,380 KB
testcase_23 AC 45 ms
6,140 KB
testcase_24 AC 91 ms
6,176 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 83 ms
6,192 KB
testcase_27 AC 86 ms
6,160 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 86 ms
6,172 KB
testcase_31 AC 82 ms
6,072 KB
testcase_32 AC 48 ms
4,668 KB
testcase_33 AC 89 ms
6,136 KB
testcase_34 AC 77 ms
5,884 KB
testcase_35 AC 31 ms
4,384 KB
testcase_36 AC 12 ms
4,380 KB
testcase_37 AC 47 ms
4,620 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.stdio, std.bitmanip;


void main() {
    auto s = readln.split;
    auto N = s[0].to!int;
    auto D = s[1].to!int;
    auto K = s[2].to!long;
    auto X = N.iota.map!(_ => readln.chomp.to!int).array;

    auto st = new SegmentTree(N);
    foreach (i; 0..N) st.update(i, X[i]);

    long m = 0;
    int a;
    foreach (i; 0..N-1) {
        auto mm = st.getmax(i+1, min(N-1, i+D)) - X[i];
        if (mm > m) a = i, m = mm;

    }

    if (m <= 0)
        writeln(0);
    else {
        int b;
        foreach (i; a+1..N) {
            if (X[i] - X[a] == m) {
                b = i;
                break;
            }
        }
        writeln(m * K);
        writeln(a, " ", b);
    }
}

class SegmentTree {
    long[] table;
    int N, table_size;

    this(int n) {
        N = n;
        table_size = 1;
        while (table_size < n) table_size *= 2;
        table_size *= 2;
        table = new long[](table_size);
        fill(table, -1);
    }

    void update(int pos, long num) {
        update_rec(0, 0, table_size/2-1, pos, num);
    }

    long update_rec(int i, int left, int right, int pos, long num) {
        if (left == right) {
            table[i] = max(num, table[i]);
            return table[i];
        }
        auto mid = (left + right) / 2;
        if (pos <= mid) {
            table[i] = max(update_rec(i*2+1, left, mid, pos, num),
                           table[i*2+2]);
        }
        else {
            table[i] = max(table[i*2+1],
                           update_rec(i*2+2, mid+1, right, pos, num));
        }
        return table[i];
    }

    long getmax(int pl, int pr) {
        return getmax_rec(0, pl, pr, 0, table_size/2-1);
    }

    long getmax_rec(int i, int pl, int pr, int left, int right) {
        if (pl > right || pr < left)
            return -1;
        else if (pl <= left && right <= pr)
            return table[i];
        else
            return max(getmax_rec(i*2+1, pl, pr, left, (left+right)/2),
                       getmax_rec(i*2+2, pl, pr, (left+right)/2+1, right));
    }
}
0