結果

問題 No.753 最強王者決定戦
ユーザー fumiphysfumiphys
提出日時 2019-03-17 17:29:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 375 ms / 1,000 ms
コード長 2,325 bytes
コンパイル時間 1,078 ms
コンパイル使用メモリ 118,276 KB
実行使用メモリ 11,652 KB
最終ジャッジ日時 2023-09-21 10:54:41
合計ジャッジ時間 3,553 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 374 ms
11,652 KB
testcase_01 AC 375 ms
11,592 KB
testcase_02 AC 367 ms
11,468 KB
testcase_03 AC 369 ms
11,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}

int n = 16;
int a[16][16];
ll dp[16][1<<16];

int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      cin >> a[i][j];
      if(i > j)a[i][j] = - a[j][i];
    }
  }
  set<int> st;
  for(int i = 0; i <= 4; i++)st.insert(1<<i);
  for(int i = 0; i < (1 << 16); i++){
    int nx = __builtin_popcount(i);
    if(st.find(nx) == st.end())continue;
    if(nx == 1){
      for(int j = 0; j < n; j++){
        if((i >> j) % 2 == 1){
          dp[j][i] = 1;
          break;
        }
      }
      continue;
    }
    for(int j = i; ; j=(j-1)&i){
      if(j == 0)break;
      if(__builtin_popcount(j) * 2 != nx)continue;
      int jt = i & (~(j));
      vector<int> v, vt;
      for(int k = 0; k < n; k++){
        if((j >> k) % 2 == 1)v.pb(k);
        if((jt >> k) % 2 == 1)vt.pb(k);
      }
      for(auto c: v){
        for(auto d: vt){
          if(a[c][d] > 0)dp[c][i] += dp[c][j] * dp[d][jt];
          else dp[d][i] += dp[c][j] * dp[d][jt];
        }
      }
    }
  }
  for(int i = 0; i < n; i++){
    cout << dp[i][(1<<16)-1] << endl;
  }
	return 0;
}
0