QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#768224 | #9735. Japanese Bands | Nlll | WA | 45ms | 3596kb | C++17 | 4.0kb | 2024-11-21 03:11:26 | 2024-11-21 03:11:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxm = 25;
const ll P = 1e9 + 7;
int mm, OK, must[Maxm], f[Maxm], ok[Maxm], pd[Maxm];
int A, B, c[Maxm], p[Maxm], C[Maxm][Maxm];
vector<int> edge[Maxm];
ll c1[Maxm], c2[Maxm], inv[Maxm];
int _norm(int x)
{
return x > P ? x - P : x;
}
void adde(int x, int y)
{
edge[x].push_back(y);
edge[y].push_back(x);
}
void dfs(int x, int now)
{
if(!OK) return;
c[x] = now;
if(now == 1) A++;
else B++;
for(auto &y : edge[x])
{
if(must[y] || ok[y]) continue;
if(c[y])
{
if(c[y] != 3 - now)
{
OK = 0;
return;
}
continue;
}
dfs(y, 3 - now);
if(!OK) return;
}
}
ll C1(int x)
{
if(x < 0) return 0;
return c1[x];
}
ll C2(int x)
{
if(x < 0) return 0;
return c2[x];
}
void solve()
{
int n1, n2, m, k;
cin >> n1 >> n2 >> m >> k;
vector<pair<int, int>> limit;
int need = 0;
for(int i = 1; i <= k; i++)
{
int x, y;
cin >> x >> y;
pd[x] = pd[y] = 1;
if(x == y)
{
if(must[x]) continue;
must[x] = 1;
need++;
}
else
{
limit.push_back({x, y});
}
}
int num = 0;
mm = 0;
for(int i = 1; i <= m; i++)
{
if(!pd[i])
{
num++;
need++;
continue;
}
if(must[i]) continue;
f[++mm] = i;
}
for(auto &[x, y] : limit)
{
adde(x, y);
}
int Lim = 1 << mm;
int ans = 0;
c1[0] = c2[0] = inv[1] = 1;
for(int i = 2; i <= m; i++) inv[i] = P - P / i * inv[P % i] % P;
for(int i = 1; i <= m; i++)
{
c1[i] = c1[i - 1] * (n1 + num - i) % P * inv[i] % P;
c2[i] = c2[i - 1] * (n2 + num - i) % P * inv[i] % P;
}
for(int i = 0; i <= m; i++) C[i][0] = 1;
for(int i = 1; i <= m; i++)
{
for(int j = 1; j <= m; j++)
{
C[i][j] = _norm(C[i - 1][j] + C[i - 1][j - 1]);
}
}
for(int t = 0; t < Lim; t++)
{
int sp = 0;
OK = 1;
A = B = 0;
int now = 0, tmp = need, z = mm;
for(int i = 1; i <= mm; i++)
{
p[i] = c[f[i]] = 0;
if(t & (1 << (i - 1)))
{
ok[f[i]] = 1;
tmp++;
z--;
}
else ok[f[i]] = 0;
}
p[0] = 1;
for(int i = 1; i <= mm; i++)
{
if(!ok[f[i]] && !c[f[i]])
{
dfs(f[i], 1);
if(!OK) break;
if(A > B) swap(A, B);
if(A == 0 && B == 1)
{
sp++;
continue;
}
now = now + B;
for(int i = now; i >= A; i--)
{
p[i] = p[i - A];
if(i >= B) p[i] += p[i - B];
}
for(int i = A - 1; i >= 0; i--) p[i] = 0;
A = B = 0;
}
}
if(!OK) continue;
now += sp;
for(int k = now; k >= 0; k--)
{
int x = 0;
for(int i = 0; i <= sp; i++)
{
x = _norm(x + p[k - i] * (ll)C[sp][i] % P);
}
p[k] = x;
}
for(int i = 0; i <= now; i++)
{
if(!p[i]) continue;
ans = _norm(ans + C1(tmp + i - 1) * C2(tmp + (z - i) - 1) % P * p[i] % P);
}
}
cout << ans << "\n";
for(int i = 1; i <= m; i++)
{
must[i] = pd[i] = 0;
vector<int>().swap(edge[i]);
}
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
int T;
cin >> T;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
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:
6 4 0
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 45ms
memory: 3596kb
input:
500 481199252 336470888 8 58 4 7 7 6 4 7 2 6 2 6 2 7 8 3 8 7 8 1 2 6 2 6 1 2 1 5 3 1 6 4 2 4 4 7 2 6 2 3 7 1 4 4 5 1 2 7 6 7 8 1 8 7 5 6 4 2 4 2 8 5 5 4 6 8 5 6 3 8 1 7 1 6 7 1 5 6 6 3 1 1 2 7 3 3 1 5 5 5 8 7 3 4 6 3 8 8 7 4 1 6 2 1 8 7 4 5 2 7 3 5 2 6 4 5 4 3 2 6 2 2 2 1 1 1 500330171 987581927 10 ...
output:
724920553 11 765571349 846759476 753803601 1 946714303 144990327 1 269113412 946380890 1 0 187438187 376698469 394650242 438244754 408053494 490145748 239700440 0 487514263 797847351 8376584 16 873078610 933415828 808801372 1 612901047 691807963 587247596 0 241309872 1 354047704 264859767 1 1 257045...
result:
wrong answer 3rd lines differ - expected: '966099120', found: '765571349'