結果

問題 No.733 分身並列コーディング
ユーザー te-shte-sh
提出日時 2018-09-20 15:45:22
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 243 ms / 1,500 ms
コード長 1,642 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 91,448 KB
実行使用メモリ 5,344 KB
最終ジャッジ日時 2023-09-03 21:00:31
合計ジャッジ時間 6,998 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 224 ms
5,104 KB
testcase_04 AC 224 ms
4,380 KB
testcase_05 AC 3 ms
5,344 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 221 ms
4,376 KB
testcase_08 AC 196 ms
4,872 KB
testcase_09 AC 82 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 27 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 80 ms
4,376 KB
testcase_20 AC 82 ms
4,380 KB
testcase_21 AC 29 ms
4,380 KB
testcase_22 AC 233 ms
4,380 KB
testcase_23 AC 28 ms
4,380 KB
testcase_24 AC 28 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 197 ms
4,376 KB
testcase_29 AC 240 ms
4,376 KB
testcase_30 AC 237 ms
4,380 KB
testcase_31 AC 236 ms
4,380 KB
testcase_32 AC 11 ms
4,376 KB
testcase_33 AC 10 ms
4,380 KB
testcase_34 AC 10 ms
4,380 KB
testcase_35 AC 11 ms
4,376 KB
testcase_36 AC 11 ms
4,380 KB
testcase_37 AC 10 ms
4,376 KB
testcase_38 AC 239 ms
4,380 KB
testcase_39 AC 240 ms
4,504 KB
testcase_40 AC 237 ms
4,380 KB
testcase_41 AC 10 ms
4,376 KB
testcase_42 AC 11 ms
4,380 KB
testcase_43 AC 10 ms
4,380 KB
testcase_44 AC 238 ms
4,376 KB
testcase_45 AC 243 ms
4,376 KB
testcase_46 AC 240 ms
5,324 KB
testcase_47 AC 239 ms
4,376 KB
testcase_48 AC 239 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}

void main()
{
  int st; readV(st);
  int n; readV(n);
  int[] t; readC(n, t);

  auto td = new int[](1<<n);
  foreach (i; 1..1<<n) {
    auto j = i.bsf;
    td[i] = td[i.bitComp(j)] + t[j];
  }

  auto dp = new int[](1<<n); dp[] = n; dp[0] = 0;
  foreach (i; 1..1<<n) {
    if (td[i] <= st) {
      dp[i] = 1;
    } else {
      for (auto j = (i-1)&i; j > 0; j = (j-1)&i)
        dp[i] = min(dp[i], dp[j]+dp[i^j]);
    }
  }

  writeln(dp[$-1]);
}

pragma(inline) {
  pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; }
  pure T bitSet(T)(T n, size_t i) { return n | (T(1) << i); }
  pure T bitReset(T)(T n, size_t i) { return n & ~(T(1) << i); }
  pure T bitComp(T)(T n, size_t i) { return n ^ (T(1) << i); }

  pure T bitSet(T)(T n, size_t s, size_t e) { return n | ((T(1) << e) - 1) & ~((T(1) << s) - 1); }
  pure T bitReset(T)(T n, size_t s, size_t e) { return n & (~((T(1) << e) - 1) | ((T(1) << s) - 1)); }
  pure T bitComp(T)(T n, size_t s, size_t e) { return n ^ ((T(1) << e) - 1) & ~((T(1) << s) - 1); }

  import core.bitop;
  pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); }
  pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); }
  pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); }
}
0