結果

問題 No.753 最強王者決定戦
ユーザー te-shte-sh
提出日時 2020-02-07 18:56:39
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 118 ms / 1,000 ms
コード長 4,193 bytes
コンパイル時間 1,478 ms
コンパイル使用メモリ 144,928 KB
実行使用メモリ 20,320 KB
最終ジャッジ日時 2023-09-04 05:29:36
合計ジャッジ時間 2,608 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
20,320 KB
testcase_01 AC 115 ms
20,212 KB
testcase_02 AC 115 ms
19,800 KB
testcase_03 AC 114 ms
18,888 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.d(122): Deprecation: function `Main.IO!(makeGlobal, makeGlobal).IO.put!("{}", long).put.putMain!(c, long).putMain` function requires a dual-context, which is deprecated
Main.d-mixin-110(110):        instantiated from here: `putMain!(c, long)`
Main.d(47):        instantiated from here: `put!("{}", long)`

ソースコード

diff #

// URL: https://yukicoder.me/problems/no/753

import std.algorithm, std.array, std.container, std.math, std.range, std.typecons, std.string;

version(unittest) {} else
void main()
{
  const n = 16;
  int[][] a; io.getM(n, n, a);

  foreach (i; 0..n)
    foreach (j; i+1..n)
      a[i][j] = a[j][i] = a[i][j] == 1 ? i : j;

  auto b = new int[][](3), c = new int[][](1<<n);
  foreach (i; 0..1<<n) {
    auto j = i.popcnt;
    if (j.popcnt == 1) {
      if (j.bsf < 3)
        b[j.bsf] ~= i;
      if (j.bsf < 4)
        foreach (k; 0..n)
          if (i.bitTest(k)) c[i] ~= k;
    }
  }

  auto dp = new long[][](1<<n, n);
  foreach (bi; b[0]) dp[bi][bi.bsf] = 1;

  foreach (k; 0..3)
    foreach (bi; b[k])
      foreach (bj; b[k])
        if (!(bi&bj))
          foreach (ci; c[bi])
            foreach (cj; c[bj])
              dp[bi|bj][a[ci][cj]] += dp[bi][ci] * dp[bj][cj];

  foreach (i; 0..1<<n)
    if (i.popcnt == 8) {
      auto j = i^((1<<16)-1);
      foreach (ci; c[i])
        foreach (cj; c[j])
          dp[i|j][a[ci][cj]] += dp[i][ci] * dp[j][cj];
    }

  foreach (i; 0..n)
    io.put(dp[$-1][i]);
}

pragma(inline)
{
  import core.bitop;
  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 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)); }
}

struct BitSubsetRange(bool includeZero = false, T)
{
  private T n, i;

  this(T n) { this.n = this.i = n; }
  static if (includeZero) {
    @property pure T front() { return i&n; }
    void popFront() { i &= n; i--; }
    pure bool empty() { return i < 0; }
  } else {
    @property pure T front() { return i; }
    void popFront() { i = (i-1)&n; }
    pure bool empty() { return i <= 0; }
  }
}
auto bitSubset(bool includeZero = false, T)(T n) { return BitSubsetRange!(includeZero, T)(n); }

auto io = IO!()();
import std.stdio;
struct IO(alias IN = stdin, alias OUT = stdout)
{
  import std.conv, std.format, std.meta, std.traits, core.stdc.stdlib;

  auto getV(T...)(ref T v) { foreach (ref w; v) get(w); }
  auto getA(T)(size_t n, ref T v) if (hasAssignableElements!T)
  { v = new T(n); foreach (ref w; v) get(w); }
  auto getC(T...)(size_t n, ref T v)
  if (allSatisfy!(hasAssignableElements, T))
  {
    foreach (ref w; v) w = new typeof(w)(n);
    foreach (i; 0..n) foreach (ref w; v) get(w[i]);
  }
  auto getM(T)(size_t r, size_t c, ref T v)
  if (hasAssignableElements!T && hasAssignableElements!(ElementType!T))
  { v = new T(r); foreach (ref w; v) getA(c, w); }
  template getS(E...)
  {
    auto getS(T)(size_t n, ref T v)
    { v = new T(n); foreach (ref w; v) foreach (e; E) mixin("get(w."~e~");"); }
  }

  const struct PutConf
  {
    bool newline = true, flush, exit;
    string floatFormat = "%.10f", delimiter = " ";
  }

  auto put(alias conf = "{}", T...)(T v)
  { mixin("const PutConf c = "~conf~"; putMain!c(v);"); }
  auto putB(alias conf = "{}", S, T)(bool c, S t, T f)
  { if (c) put(t); else put(f); }
  auto putRaw(T...)(T v) { OUT.write(v); OUT.writeln; }

  private
  {
    dchar[] buf;
    auto sp = (new dchar[](0)).splitter;
    void nextLine() { IN.readln(buf); sp = buf.splitter; }
    auto get(T)(ref T v) { if (sp.empty) nextLine(); v = sp.front.to!T; sp.popFront(); }

    auto putMain(PutConf c, T...)(T v)
    {
      foreach (i, w; v) {
        putOne!c(w);
        if (i < v.length-1) OUT.write(c.delimiter);
      }
      static if (c.newline) OUT.writeln;
      static if (c.flush) OUT.flush();
      static if (c.exit) exit(0);
    }
    auto putOne(PutConf c, T)(T v)
    {
      static if (isInputRange!T && !isSomeString!T) putRange!c(v);
      else if (isFloatingPoint!T) OUT.write(format(c.floatFormat, v));
      else OUT.write(v);
    }
    auto putRange(PutConf c, T)(T v)
    {
      auto w = v;
      while (!w.empty) {
        putOne!c(w.front); w.popFront();
        if (!w.empty) OUT.write(c.delimiter);
      }
    }
  }
}
0