結果

問題 No.489 株に挑戦
ユーザー te-shte-sh
提出日時 2017-12-11 17:36:41
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 47 ms / 1,000 ms
コード長 1,524 bytes
コンパイル時間 649 ms
コンパイル使用メモリ 88,424 KB
実行使用メモリ 19,908 KB
最終ジャッジ日時 2023-09-03 17:28:01
合計ジャッジ時間 2,920 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
14,412 KB
testcase_01 AC 22 ms
10,040 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 39 ms
17,064 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 23 ms
10,556 KB
testcase_19 AC 18 ms
8,560 KB
testcase_20 AC 41 ms
17,556 KB
testcase_21 AC 10 ms
5,604 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 25 ms
10,828 KB
testcase_24 AC 47 ms
19,908 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 41 ms
18,212 KB
testcase_27 AC 44 ms
18,344 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 47 ms
19,860 KB
testcase_31 AC 44 ms
18,476 KB
testcase_32 AC 25 ms
10,812 KB
testcase_33 AC 44 ms
18,872 KB
testcase_34 AC 38 ms
16,204 KB
testcase_35 AC 16 ms
7,760 KB
testcase_36 AC 7 ms
5,880 KB
testcase_37 AC 24 ms
11,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd = readln.split.to!(int[]), n = rd[0], d = rd[1], k = rd[2];
  auto x = new int[](n);
  foreach (i; 0..n) x[i] = readln.chomp.to!int;

  auto st = SparseTable!(int, max)(x);
  auto ri = 0, rp = 0, rs = 0;
  foreach (i; 0..n-1) {
    auto p = st[i+1..min(i+1+d,n)], s = p-x[i];
    if (s > rs) {
      ri = i;
      rp = p;
      rs = s;
    }
  }

  if (rs == 0) {
    writeln(0);
    return;
  }

  writeln(k.to!long * rs);
  write(ri, " ");
  foreach (i; ri+1..n)
    if (x[i] == rp) {
      writeln(i);
      break;
    }
}

struct SparseTable(T, alias pred = "a < b ? a : b")
{
  import std.algorithm, std.functional;
  alias predFun = binaryFun!pred;

  size_t[] logTable;
  size_t[][] rmq;
  size_t n;
  T[] a;

  this(T[] a)
  {
    this.a = a;
    this.n = a.length;

    logTable = new size_t[n + 1];
    foreach (i; 2..n+1)
      logTable[i] = logTable[i >> 1] + 1;

    rmq = new size_t[][](logTable[n] + 1, n);

    foreach (i; 0..n)
      rmq[0][i] = i;

    for (size_t k = 1; (1 << k) < n; ++k)
      for (size_t i = 0; i + (1 << k) <= n; ++i) {
        auto x = rmq[k - 1][i];
        auto y = rmq[k - 1][i + (1 << k - 1)];
        rmq[k][i] = predFun(a[x], a[y]) == a[x] ? x : y;
      }
  }

  pure size_t opDollar() const { return n; }

  pure T opSlice(size_t l, size_t r) const
  {
    auto k = logTable[r - l - 1];
    auto x = rmq[k][l];
    auto y = rmq[k][r - (1 << k)];
    return predFun(a[x], a[y]);
  }
}
0