結果
| 問題 |
No.519 アイドルユニット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-01-26 12:18:20 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,313 bytes |
| コンパイル時間 | 650 ms |
| コンパイル使用メモリ | 98,780 KB |
| 実行使用メモリ | 82,112 KB |
| 最終ジャッジ日時 | 2024-06-12 23:38:21 |
| 合計ジャッジ時間 | 5,010 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 33 |
ソースコード
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);
int search(int i)
{
if (i == 0) return 0;
if (memo[i]) return memo[i];
auto j = i.bsf, r = 0;
foreach (k; j+1..n) {
if (!i.bitTest(k)) continue;
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)); }
}