提出 #46889434


ソースコード 拡げる

#include<bits/stdc++.h>
#define LL long long
#define DB double
#define MOD 1000000007
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define lowbit(x) ((-x) & x)
#define MP make_pair
#define MT make_tuple
#define VI vector<int>
#define VL vector<LL>
#define VII VI::iterator
#define VLI VL::iterator
#define all(x) x.begin(), x.end()
#define EB emplace_back
#define PII pair<int, int>
#define SI set<int>
#define SII SI::iterator
#define fi first
#define se second
using namespace std;
template<typename T> void chkmn(T &a, const T b) { (a > b) && (a = b); }
template<typename T> void chkmx(T &a, const T b) { (a < b) && (a = b); }
void Inc(int &a, const int &b) { ((a += b) >= MOD) && (a -= MOD); }
void Dec(int &a, const int &b) { ((a -= b) < 0) && (a += MOD); }
void Mul(int &a, const int &b) { a = 1LL * a * b % MOD; }
void Sqr(int &a) { a = 1LL * a * a % MOD; }
int inc(const int &a, const int &b) { return (a + b >= MOD) ? a + b - MOD : a + b; }
int dec(const int &a, const int &b) { return (a - b < 0) ? a - b + MOD : a - b; }
int mul(const int &a, const int &b) { return 1LL * a * b % MOD; }
int sqr(const int &a) { return 1LL * a * a % MOD; }
int qwqmi(int x, int k = MOD - 2)
{
	int res = 1;
	while(k)
	{
		if(k & 1) Mul(res, x);
		k >>= 1, Sqr(x);
	}
	return res;
}
const int N = 21;
const int M = 1 << N;
int n, a[N][N];
int f[2][M];
vector<int> State[N];
int main()
{
	scanf("%d", &n);
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < n; ++j)
			scanf("%d", &a[i][j]);
	for(int S = 0; S < (1 << n); ++S)
		State[__builtin_popcount(S)].EB(S);
	int now = 0, lst = 1;
	f[0][(1 << n) - 1] = 1;
	for(int i = 0; i < n; ++i)
	{
		swap(now, lst);
		memset(f[now], 0, sizeof(f[now]));
		for(auto S : State[n - i])
		{
			for(int j = 0; j < n; ++j)
				if(a[i][j] && ((S >> j) & 1))
					Inc(f[now][S ^ (1 << j)], f[lst][S]);
		}
	}
	printf("%d\n", f[now][0]);
	return 0;
}


提出情報

提出日時
問題 O - Matching
ユーザ Schucking_Sattin
言語 C++ 20 (gcc 12.2)
得点 100
コード長 1954 Byte
結果 AC
実行時間 152 ms
メモリ 29268 KiB

コンパイルエラー

Main.cpp: In function ‘int main()’:
Main.cpp:49:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   49 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
Main.cpp:52:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   52 |                         scanf("%d", &a[i][j]);
      |                         ~~~~~^~~~~~~~~~~~~~~~

ジャッジ結果

セット名 All
得点 / 配点 100 / 100
結果
AC × 17
セット名 テストケース
All 0_00, 0_01, 0_02, 0_03, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12
ケース名 結果 実行時間 メモリ
0_00 AC 8 ms 19972 KiB
0_01 AC 9 ms 20232 KiB
0_02 AC 4 ms 12000 KiB
0_03 AC 87 ms 29124 KiB
1_00 AC 4 ms 11900 KiB
1_01 AC 4 ms 12064 KiB
1_02 AC 51 ms 29156 KiB
1_03 AC 56 ms 29268 KiB
1_04 AC 62 ms 29124 KiB
1_05 AC 68 ms 29132 KiB
1_06 AC 74 ms 29164 KiB
1_07 AC 77 ms 29204 KiB
1_08 AC 114 ms 29164 KiB
1_09 AC 108 ms 29156 KiB
1_10 AC 122 ms 29164 KiB
1_11 AC 138 ms 29132 KiB
1_12 AC 152 ms 29180 KiB