結果

問題 No.913 木の燃やし方
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-10-18 22:48:09
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 2,670 bytes
コンパイル時間 967 ms
コンパイル使用メモリ 123,752 KB
実行使用メモリ 43,784 KB
最終ジャッジ日時 2023-09-04 03:07:34
合計ジャッジ時間 27,912 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 16 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 969 ms
35,260 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1,045 ms
38,248 KB
testcase_13 AC 601 ms
38,572 KB
testcase_14 AC 576 ms
35,740 KB
testcase_15 AC 586 ms
35,240 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 696 ms
32,812 KB
testcase_20 AC 722 ms
32,932 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 698 ms
34,572 KB
testcase_25 AC 664 ms
32,200 KB
testcase_26 AC 620 ms
39,872 KB
testcase_27 AC 617 ms
38,984 KB
testcase_28 AC 706 ms
36,428 KB
testcase_29 AC 811 ms
36,156 KB
testcase_30 AC 988 ms
35,944 KB
testcase_31 AC 793 ms
40,980 KB
testcase_32 AC 768 ms
43,784 KB
testcase_33 AC 743 ms
38,952 KB
testcase_34 AC 853 ms
37,240 KB
testcase_35 AC 867 ms
37,932 KB
testcase_36 AC 773 ms
34,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

enum INF = 10L^^18;
enum W = 100;

int N;
long[] A;

long[] ASum;

alias Entry = Tuple!(long, int);
Entry[][] es;

long f(int i, int j) {
  return (cast(long)(j - i))^^2 + (ASum[j] - ASum[i]);
}

void solve(int dir, int iL, int iR, int jL, int jR) {
  if (iL == iR) return;
  const iMid = (iL + iR) / 2;
  long opt = INF;
  int jm = jL;
  foreach (j; jL - W .. jR + W) {
    if (iMid < j && j <= N) {
      if (chmin(opt, f(iMid, j))) {
        jm = j;
      }
    }
  }
  if (dir == 0) {
    es[iMid] ~= Entry(opt, jm);
  } else {
    es[N - jm] ~= Entry(opt, N - iMid);
  }
  solve(dir, iL, iMid, jL, jm + 1);
  solve(dir, iMid + 1, iR, jm, jR);
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      A = new long[N];
      foreach (i; 0 .. N) {
        A[i] = readLong();
      }
      
      es = new Entry[][N];
      foreach (dir; 0 .. 2) {
        ASum = new long[N + 1];
        foreach (i; 0 .. N) {
          ASum[i + 1] = ASum[i] + A[i];
        }
        solve(dir, 0, N, 0, N + 1);
        A.reverse();
      }
      debug {
        writeln("es = ", es);
      }
      
      BinaryHeap!(Array!Entry, "a > b") que;
      auto ans = new long[N];
      foreach (i; 0 .. N) {
        foreach (e; es[i]) {
          que.insert(e);
        }
        for (; !que.empty; que.removeFront) {
          if (i < que.front[1]) {
            ans[i] = que.front[0];
            break;
          }
        }
      }
      foreach (i; 0 .. N) {
        writeln(ans[i]);
      }
    }
  } catch (EOFException e) {
  }
}
0