結果

問題 No.158 奇妙なお使い
ユーザー 👑 hos.lyrichos.lyric
提出日時 2015-02-26 23:45:03
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 216 ms / 5,000 ms
コード長 3,036 bytes
コンパイル時間 768 ms
コンパイル使用メモリ 109,744 KB
実行使用メモリ 60,480 KB
最終ジャッジ日時 2023-09-02 20:07:19
合計ジャッジ時間 3,719 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
47,644 KB
testcase_01 AC 31 ms
48,128 KB
testcase_02 AC 30 ms
47,308 KB
testcase_03 AC 30 ms
48,352 KB
testcase_04 AC 190 ms
60,480 KB
testcase_05 AC 29 ms
48,036 KB
testcase_06 AC 29 ms
48,328 KB
testcase_07 AC 29 ms
47,656 KB
testcase_08 AC 30 ms
47,720 KB
testcase_09 AC 29 ms
47,436 KB
testcase_10 AC 31 ms
47,548 KB
testcase_11 AC 29 ms
48,056 KB
testcase_12 AC 30 ms
47,712 KB
testcase_13 AC 30 ms
48,100 KB
testcase_14 AC 31 ms
47,332 KB
testcase_15 AC 35 ms
48,028 KB
testcase_16 AC 33 ms
48,904 KB
testcase_17 AC 52 ms
48,888 KB
testcase_18 AC 53 ms
49,136 KB
testcase_19 AC 29 ms
47,772 KB
testcase_20 AC 42 ms
47,836 KB
testcase_21 AC 196 ms
48,608 KB
testcase_22 AC 216 ms
50,192 KB
testcase_23 AC 30 ms
48,372 KB
testcase_24 AC 30 ms
47,652 KB
testcase_25 AC 30 ms
48,072 KB
testcase_26 AC 33 ms
49,144 KB
testcase_27 AC 30 ms
48,888 KB
testcase_28 AC 45 ms
49,436 KB
testcase_29 AC 35 ms
49,180 KB
testcase_30 AC 64 ms
48,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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) {}
}
0