QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#800343#9735. Japanese BandsSGColinWA 0ms3796kbC++202.0kb2024-12-06 09:18:562024-12-06 09:18:57

Judging History

你现在查看的是最新测评结果

  • [2025-01-18 23:34:05]
  • hack成功,自动添加数据
  • (/hack/1459)
  • [2024-12-06 09:18:57]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3796kb
  • [2024-12-06 09:18:56]
  • 提交

answer

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;

inline int rd() {
	int x = 0;
	bool f = 0;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) f |= (c == '-');
	for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
	return f ? -x : x;
}

#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)

constexpr int N = 20;
constexpr int mod = 1000000007;

int inv[N], sum[1 << N];

ll fpow(ll x, int t) {
	ll ret = 1;
	for (; t; t >>= 1, x = x * x % mod)
		if (t & 1) ret = ret * x % mod;
	return ret;
}

ll C(int n, int m) {
	if (n < m || m < 0) return 0;
	ll ret = 1;
	rep(i, 1, m) ret = ret * (n - i + 1) % mod * inv[i] % mod;
	return ret;
}

inline int mo(int x) {return x >= mod ? x - mod : x;}

inline void work() {
	int n1 = rd(), n2 = rd(), m = rd(), k = rd(), m0 = 0, M = 0;

	vii lims;
	vi mark(m, 0), tr(m, -1), lim(m, 0), tmp, oks;
	rep(i, 1, k) {
		int u = rd() - 1, v = rd() - 1;
		mark[u] = mark[v] = true;
		lims.eb(u, v);
	}
	rep(i, 0, m - 1) {
		if (!mark[i]) ++m0;
		else tr[i] = ++M;
	}
	for (auto [u, v] : lims) {
		lim[tr[u]] |= (1 << tr[v]);
		lim[tr[v]] |= (1 << tr[u]);
	}
	
	rep(S, 0, (1 << M) - 1) {
		sum[S] = 0;
		bool flg = true;
		rep(i, 0, M - 1) 
			if (((S >> i) & 1) && (S & lim[i])) {
				flg = false; break;
			} 
		if (!flg) continue;
		oks.eb(S); 
		sum[S] = C(n1 + m0 - 1, m - __builtin_popcount(S) - 1);
	}
	rep(i, 0, M - 1) 
		rep(S, 0, (1 << M) - 1) 
			if ((S >> i) & 1) 
				sum[S] = mo(sum[S] + sum[S ^ (1 << i)]);

	ll ans = 0;
	for (auto S : oks) {
		ll coef = C(n2 + m0 - 1, m - __builtin_popcount(S) - 1);
		ans = (ans + coef * sum[(1 << M) - 1 - S]) % mod;
	}	
	printf("%lld\n", ans);
}

int main() {
	inv[0] = inv[1] = 1;
	rep(i, 2, N - 1) inv[i] = fpow(i, mod - 2);
	per(t, rd(), 1) work();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3796kb

input:

3
2 3 3 3
2 3
1 1
2 3
2 2 2 1
1 1
1 1 10 2
1 2
1 3

output:

7
8
0

result:

wrong answer 1st lines differ - expected: '6', found: '7'