結果
| 問題 |
No.37 遊園地のアトラクション
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-09-03 18:00:53 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,201 bytes |
| コンパイル時間 | 1,146 ms |
| コンパイル使用メモリ | 117,120 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-12 04:08:33 |
| 合計ジャッジ時間 | 2,228 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 WA * 7 |
ソースコード
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.conv, std.stdio, std.typecons;
void main()
{
auto t = readln.chomp.to!int;
auto n = readln.chomp.to!int;
auto ci = readln.split.map!(to!int).array;
auto vi = readln.split.map!(to!int).array;
auto memo = new int[](t + 1);
memo[0] = 0;
memo[1..$] = -1;
foreach (i; 0..n) {
auto memo2 = new int[](t + 1);
memo2[] = -1;
auto dvi = calcDvi(vi[i]);
foreach (j; ci[i]..t + 1) {
if (memo[j - ci[i]] >= 0) {
foreach (k, dv; dvi) {
auto m = j + k * ci[i];
if (m <= t) {
if (memo2[m] >= 0)
memo2[m] = max(memo[j - ci[i]], dv);
else
memo2[m] = memo[j - ci[i]] + dv;
}
}
}
}
foreach (j; 0..t + 1) {
if (memo2[j] >= 0) {
if (memo[j] >= 0)
memo[j] = max(memo[j], memo2[j]);
else
memo[j] = memo2[j];
}
}
}
writeln(memo.reduce!(max));
}
int[] calcDvi(int v)
{
int[] dvi;
for (auto c = v; v > 0; v /= 2, c+= v)
dvi ~= c;
return dvi;
}