結果
問題 | No.158 奇妙なお使い |
ユーザー | 👑 hos.lyric |
提出日時 | 2015-02-26 23:45:03 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 173 ms / 5,000 ms |
コード長 | 3,036 bytes |
コンパイル時間 | 1,031 ms |
コンパイル使用メモリ | 122,364 KB |
実行使用メモリ | 59,480 KB |
最終ジャッジ日時 | 2024-06-12 02:30:18 |
合計ジャッジ時間 | 3,313 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
47,016 KB |
testcase_01 | AC | 29 ms
47,292 KB |
testcase_02 | AC | 29 ms
48,364 KB |
testcase_03 | AC | 28 ms
48,144 KB |
testcase_04 | AC | 168 ms
59,480 KB |
testcase_05 | AC | 28 ms
47,340 KB |
testcase_06 | AC | 27 ms
47,172 KB |
testcase_07 | AC | 28 ms
48,244 KB |
testcase_08 | AC | 28 ms
47,572 KB |
testcase_09 | AC | 27 ms
47,852 KB |
testcase_10 | AC | 27 ms
48,068 KB |
testcase_11 | AC | 28 ms
47,588 KB |
testcase_12 | AC | 27 ms
47,572 KB |
testcase_13 | AC | 27 ms
48,012 KB |
testcase_14 | AC | 29 ms
47,208 KB |
testcase_15 | AC | 32 ms
47,460 KB |
testcase_16 | AC | 31 ms
47,008 KB |
testcase_17 | AC | 47 ms
47,992 KB |
testcase_18 | AC | 47 ms
48,044 KB |
testcase_19 | AC | 27 ms
48,684 KB |
testcase_20 | AC | 38 ms
48,080 KB |
testcase_21 | AC | 172 ms
48,300 KB |
testcase_22 | AC | 173 ms
49,860 KB |
testcase_23 | AC | 27 ms
47,252 KB |
testcase_24 | AC | 28 ms
46,972 KB |
testcase_25 | AC | 28 ms
47,824 KB |
testcase_26 | AC | 31 ms
48,728 KB |
testcase_27 | AC | 27 ms
47,940 KB |
testcase_28 | AC | 40 ms
48,648 KB |
testcase_29 | AC | 32 ms
48,712 KB |
testcase_30 | AC | 57 ms
47,924 KB |
ソースコード
import core.thread; import std.conv, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex; // Input class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { tokens = readln.split; if (tokens.empty && stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; } int readInt() { return to!int(readToken); } long readLong() { return to!long(readToken); } real readReal() { return to!real(readToken); } // chmin/chmax void chmin(T)(ref T t, in T f) { if (t > f) t = f; } void chmax(T)(ref T t, in T f) { if (t < f) t = f; } // Pair struct Pair(S, T) { S x; T y; int opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; } int opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; } string toString() const { return "(" ~ to!string(x) ~ ", " ~ to!string(y) ~ ")"; } } auto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); } // Array int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; } int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); } int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); } T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; } immutable L = 10000; immutable A = 1000; immutable B = 100; immutable C = 1; int SA, SB, SC; int[2] D, TA, TB, TC, UA, UB, UC; void main(string[] args) { try { for (; ; ) { SA = readInt; SB = readInt; SC = readInt; foreach (i; 0 .. 2) { D[i] = readInt; TA[i] = readInt; TB[i] = readInt; TC[i] = readInt; } foreach (i; 0 .. 2) { UA[i] = D[i] / A; UB[i] = D[i] % A / B; UC[i] = D[i] % B / C; debug{ writeln(UA[i]," ",UB[i]," ",UC[i]); } } int[][][] dp = new int[][][](L / A + 1, L / B + 1, L / C + 1); foreach (a; 0 .. L / A + 1) foreach (b; 0 .. L / B + 1) foreach (c; 0 .. L / C + 1) { dp[a][b][c] = -1; } int calc(int a, int b, int c) { if (dp[a][b][c] == -1) { int ret; if (a + 1 <= L / A && b >= A / B) { chmax(ret, calc(a + 1, b - A / B, c)); } if (b + 1 <= L / B && c >= B / C) { chmax(ret, calc(a, b + 1, c - B / C)); } foreach (i; 0 .. 2) { if (a >= UA[i] && b >= UB[i] && c >= UC[i]) { const aa = a - UA[i] + TA[i]; const bb = b - UB[i] + TB[i]; const cc = c - UC[i] + TC[i]; if (aa <= L / A && bb <= L / B && cc <= L / C) { chmax(ret, 1 + calc(aa, bb, cc)); } } } debug{ writeln("calc ",a," ",b," ",c," = ",ret); } dp[a][b][c] = ret; } return dp[a][b][c]; } const ans = calc(SA, SB, SC); writeln(ans); } } catch (EOFException) {} }