結果

問題 No.519 アイドルユニット
ユーザー te-shte-sh
提出日時 2018-01-26 14:18:25
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 55 ms / 1,000 ms
コード長 1,294 bytes
コンパイル時間 582 ms
コンパイル使用メモリ 83,728 KB
実行使用メモリ 69,344 KB
最終ジャッジ日時 2023-09-03 18:22:56
合計ジャッジ時間 2,424 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
69,288 KB
testcase_01 AC 55 ms
68,528 KB
testcase_02 AC 16 ms
19,368 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 4 ms
5,392 KB
testcase_14 AC 4 ms
4,384 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 4 ms
5,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 3 ms
4,820 KB
testcase_24 AC 6 ms
7,916 KB
testcase_25 AC 6 ms
7,172 KB
testcase_26 AC 7 ms
8,464 KB
testcase_27 AC 5 ms
7,700 KB
testcase_28 AC 6 ms
7,392 KB
testcase_29 AC 52 ms
68,340 KB
testcase_30 AC 53 ms
68,876 KB
testcase_31 AC 53 ms
68,772 KB
testcase_32 AC 52 ms
69,344 KB
testcase_33 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
T[] readArray(T)(size_t n){auto a=new T[](n),r=readln.splitter;foreach(ref v;a){v=r.front.to!T;r.popFront;}return a;}
T[] readArrayM(T)(size_t n){auto a=new T[](n);foreach(ref v;a)v=readln.chomp.to!T;return a;}

void main()
{
  int n; readV(n);
  auto f = new int[][](n);
  foreach (i; 0..n) f[i] = readArray!int(n);

  auto memo = new int[](1<<n);
  memo[1..$] = -1;

  int search(int i)
  {
    if (memo[i] >= 0) return memo[i];

    auto j = i.bsf, r = 0;
    foreach (k; j+1..n)
      if (i.bitTest(k))
        r = max(r, search(i.bitReset(j).bitReset(k))+f[j][k]);

    return memo[i] = r;
  }

  writeln(search((1<<n)-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); }

  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