結果

問題 No.733 分身並列コーディング
ユーザー nebukuro09
提出日時 2018-09-11 13:56:44
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 956 bytes
コンパイル時間 883 ms
コンパイル使用メモリ 116,992 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-06-13 01:39:15
合計ジャッジ時間 4,051 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 2 TLE * 1 -- * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10^^9 + 7;
immutable long INF = 1L << 59;

void main() {
    auto T = readln.chomp.to!int;
    auto N = readln.chomp.to!int;
    auto A = N.iota.map!(_ => readln.chomp.to!int).array;

    auto mem = new int[](1 << N);
    fill(mem, -1);

    auto cost = (1 << N).iota.map!(mask => N.iota.filter!(i => (1 << i) & mask).map!(i => A[i]).sum);

    int dfs(int mask) {
        if (mask == 0) return 0;
        if (mem[mask] >= 0) return mem[mask];

        int ret = 1 << 29;
        for(int nmask = mask; nmask > 0; nmask = (nmask-1) & mask) {
            if (cost[mask] <= T) {
                ret = min(ret, dfs(mask ^ nmask) + 1);
            }
        }

        mem[mask] = ret;
        return ret;
    }

    dfs((1 << N) - 1).writeln;
}
0