結果

問題 No.2445 奇行列式
コンテスト
ユーザー shobonvip
提出日時 2023-08-26 01:45:50
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,701 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,308 ms
コンパイル使用メモリ 226,676 KB
最終ジャッジ日時 2026-07-02 07:23:41
合計ジャッジ時間 1,888 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:76,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/algorithm:62,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:53,
                 from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bit: In instantiation of 'constexpr int std::__popcount(_Tp) [with _Tp = int]':
main.cpp:68:18:   required from here
   68 |                         if (__popcount(i) != num) continue;
      |                             ~~~~~~~~~~^~~
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bit:308:34: error: argument 1 in call to function '__builtin_popcountg' has signed type
  308 |       return __builtin_popcountg(__x);
      |                                  ^~~

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

int main(){
	int n; cin >> n;
	int b; cin >> b;
	mint::set_mod(b);
	vector<vector<mint>> a(n, vector<mint>(n));
	rep(i,0,n){
		rep(j,0,n){
			ll x; cin >> x;
			a[i][j] = x;
		}
	}
	vector<mint> odp(1<<n);
	vector<mint> edp(1<<n);
	edp[0] = 1;
	rep(num,1,n+1){
		rep(i,0,1<<n){
			if (__popcount(i) != num) continue;
			int cnt = 0;
			rrep(j,0,n){
				if (i >> j & 1){
					if (cnt % 2 == 0){
						edp[i] += edp[i ^ (1<<j)] * a[num-1][j];
						odp[i] += odp[i ^ (1<<j)] * a[num-1][j];
					}else{
						edp[i] += odp[i ^ (1<<j)] * a[num-1][j];
						odp[i] += edp[i ^ (1<<j)] * a[num-1][j];
					}
					cnt++;
				}
			}
		}
	}
	cout << odp[(1<<n)-1].val() << '\n';
}

0