結果

問題 No.1937 Various Tournament
ユーザー そすうぽよそすうぽよ
提出日時 2022-05-13 23:07:30
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,955 bytes
コンパイル時間 2,759 ms
使用メモリ 12,904 KB
最終ジャッジ日時 2023-02-21 16:52:06
合計ジャッジ時間 66,434 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
6,204 KB
testcase_01 AC 1,835 ms
11,464 KB
testcase_02 AC 1,939 ms
12,144 KB
testcase_03 TLE -
testcase_04 AC 1,919 ms
12,160 KB
testcase_05 AC 2 ms
6,248 KB
testcase_06 TLE -
testcase_07 TLE -
testcase_08 AC 2 ms
6,272 KB
testcase_09 AC 1,946 ms
12,236 KB
testcase_10 AC 1 ms
6,256 KB
testcase_11 AC 1,999 ms
12,520 KB
testcase_12 AC 1,949 ms
12,340 KB
testcase_13 TLE -
testcase_14 AC 1,953 ms
12,320 KB
testcase_15 TLE -
testcase_16 AC 1,971 ms
12,268 KB
testcase_17 AC 1,856 ms
11,708 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 AC 2 ms
6,172 KB
testcase_21 AC 2 ms
6,272 KB
testcase_22 TLE -
testcase_23 AC 1,971 ms
12,188 KB
testcase_24 AC 1,992 ms
12,676 KB
testcase_25 AC 2 ms
6,280 KB
testcase_26 TLE -
testcase_27 AC 2 ms
6,196 KB
testcase_28 AC 1,835 ms
11,528 KB
testcase_29 AC 2 ms
6,272 KB
testcase_30 TLE -
testcase_31 AC 1,896 ms
12,000 KB
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 AC 1,985 ms
12,480 KB
testcase_36 AC 1,976 ms
12,412 KB
testcase_37 AC 1 ms
6,196 KB
testcase_38 AC 1 ms
6,196 KB
testcase_39 AC 1,995 ms
12,472 KB
testcase_40 AC 2 ms
6,276 KB
testcase_41 AC 2 ms
6,256 KB
testcase_42 TLE -
testcase_43 AC 1 ms
6,252 KB
testcase_44 AC 2 ms
6,172 KB
testcase_45 TLE -
testcase_46 AC 2 ms
6,260 KB
testcase_47 AC 2 ms
6,208 KB
testcase_48 AC 1 ms
6,196 KB
testcase_49 AC 1 ms
6,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <variant>

#define rep2(i,k,n) for(i64 i=(i64)(k);i<(i64)(n);i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) begin(x),end(x)
#ifdef ENV_LOCAL
#define dump if (1) cerr
#else
#define dump if (0) cerr
#endif
 
using namespace std;
using namespace std::string_literals;
 
using i32 = int32_t;
using i64 = int64_t;
using f64 = double;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;

i64 permanent(const vector<vi32>& s) {
  i64 n = size(s);
  i64 ans = 0;
  rep(i,1<<n) {
    i64 prod = 1;
    rep(j,n) {
      i64 sum = 0;
      rep(k,n) {
        if ((i>>k)&1) {
          sum += s[j][k];
        }
      }
      prod *= sum;
    }
    if (__builtin_popcount(i) % 2) prod *= -1;
    ans += prod;
  }
  if (n % 2) ans *= -1;
  return ans;
}
map<vector<vi32>, vi64> cache;
vi64 solve(const vector<vi32>& s) {
  i64 n = size(s);
  if (n == 1) {
    return {1};
  }
  if (n == 2) {
    if (s[0][1]) {
      return {2, 0};
    } else {
      return {0, 2};
    }
  }
  if (cache.count(s)) {
    return cache.at(s);
  }
  vi64 ans(n);
  rep(i,1<<n) {
    if (__builtin_popcount(i) != n/2) continue;
    vi32 winner;
    vi32 loser;
    rep(j,n) {
      if ((i>>j)&1) {
        winner.push_back(j);
      } else {
        loser.push_back(j);
      }
    }
    vector<vi32> mat(n/2, vi32(n/2));
    rep(j,n/2)rep(k,n/2) {
      mat[j][k] = s[winner[j]][loser[k]];
    }
    i64 cnt = permanent(mat);
    vector<vi32> ss(n/2, vi32(n/2));
    rep(j,n/2)rep(k,n/2) {
      ss[j][k] = s[winner[j]][winner[k]];
    }
    auto sans = solve(ss);
    cnt *= (1 << (n/2));
    rep(j,n/2) {
      ans[winner[j]] += cnt * sans[j];
    }
  }
  cache[s] = ans;
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 n;
  cin>>n;
  vector<vi32> s(n, vi32(n));
  rep(i,n)rep(j,n) {
    cin>> s[i][j] ;
  }
  vi64 ans = solve(s);
  rep(i,n) {
    cout<<ans[i]<<endl;
  }
  return 0;
}
0