結果

問題 No.37 遊園地のアトラクション
ユーザー nebukuro09
提出日時 2016-11-17 13:28:52
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 713 bytes
コンパイル時間 738 ms
コンパイル使用メモリ 112,232 KB
実行使用メモリ 263,136 KB
最終ジャッジ日時 2024-06-12 05:07:19
合計ジャッジ時間 7,186 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 4
other AC * 1 WA * 1 TLE * 1 -- * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;
import std.numeric;

int T, N;
int[] C, V;
int[long] mem;

int rec(long b, int t, int acm) {
  if (b in mem)
    return mem[b];

  mem[b] = acm;
  foreach (i; iota(N)) {
    auto b2 = b / 10^^i % 10;
    if (t > C[i] && (V[i] >> b2) > 0 &&  b2 < 9)
      mem[b] = max(mem[b], rec(b+(b2+1)*(10^^i), t-C[i], acm+(V[i]>>b2)));
  }
  return mem[b];
}

void main() {
  T = readln.chomp.to!int;
  N = readln.chomp.to!int;
  C = readln.split.map!(to!int).array;
  V = readln.split.map!(to!int).array;
  writeln(rec(0L, T, 0));
}
0