結果
問題 | No.2700 Please Hack Greedy Solution! |
ユーザー |
👑 |
提出日時 | 2024-03-30 00:06:16 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 3 ms / 500 ms |
コード長 | 2,341 bytes |
コンパイル時間 | 1,546 ms |
コンパイル使用メモリ | 104,020 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-01-06 11:38:20 |
合計ジャッジ時間 | 2,240 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 1 |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string;import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, 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; }string COLOR(string s = "") { return "\x1b[" ~ s ~ "m"; }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)); }void main() {/*const N = 2;const W = 3;const V = [3, 4];const X = [1, 2];*//*V[1, N]V[x] > V[1] + V[x-1] (x >= 3)V[1]/1 > V[x]/xV[x] = a x + b (x >= 3)*/const N = 1000;const W = 1000;int[] V, X;V ~= W;X ~= 1;{const a = W + 1;const b = W + 1;foreach_reverse (x; 2 .. W + 1) {V ~= a * x - b;X ~= x;}}writeln(N, " ", W);foreach (i; 0 .. N) {writeln(V[i], " ", X[i]);}foreach (i; 0 .. N - 1) {const det = V[i] * X[i + 1] - V[i + 1] * X[i];assert(det > 0 || (det == 0 && X[i] >= X[i + 1]));}auto fs = new int[W + 1];foreach (i; 0 .. N) {foreach_reverse (x; 0 .. W - X[i] + 1) chmax(fs[x + X[i]], fs[x] + V[i]);}auto gs = new int[W + 1];foreach (x; 0 .. W + 1) {int xx = x;foreach (i; 0 .. N) {if (xx >= X[i]) {xx -= X[i];gs[x] += V[i];}}}debug {writeln("fs = ", fs);writeln("gs = ", gs);foreach (x; 1 .. W + 1) {assert(fs[x] >= gs[x]);if (fs[x] == gs[x]) {writeln("match x = ", x);}}}}