QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#737121 | #2209. Good Game | hhoppitree | WA | 9ms | 11724kb | C++17 | 2.3kb | 2024-11-12 14:41:15 | 2024-11-12 14:41:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 55, M = 1e6 + 5, P = 1e9 + 7;
int ksm(int x, int y = P - 2) {
int res = 1;
while (y) {
if (y & 1) res = 1ll * res * x % P;
x = 1ll * x * x % P;
y >>= 1;
}
return res;
}
int n, m, a[N][N], f[N], fac[M], iFac[M], o[N][N];
int det() {
int res = 1;
for (int i = 0; i < m; ++i) {
int wh = -1;
for (int j = i; j < m; ++j) {
if (o[j][i]) {
wh = j;
break;
}
}
if (!~wh) return 0;
if (wh != i) swap(o[wh], o[i]), res *= -1;
res = 1ll * res * o[i][i] % P;
for (int j = i + 1; j < m; ++j) {
int coef = 1ll * o[j][i] * ksm(o[i][i]) % P;
for (int k = i; k < m; ++k) {
o[j][k] = (o[j][k] - 1ll * coef * o[i][k]) % P;
}
}
}
return res;
}
int calc(int x, int y) {
int s = 0;
for (int i = 0; i < m; ++i) {
if (a[x][i] > a[y][i]) return 0;
s += a[y][i] - a[x][i];
}
for (int i = 0; i < m; ++i) {
for (int j = 0; j < m; ++j) {
o[i][j] = (a[x][i] > a[y][j] ? 0 : iFac[a[y][j] - a[x][i]]);
}
}
return 1ll * fac[s] * det() % P;
}
int ord[N];
int cmp(int x, int y) {
return accumulate(a[x], a[x] + m, 0) < accumulate(a[y], a[y] + m, 0);
}
signed main() {
for (int i = fac[0] = 1; i < M; ++i) {
fac[i] = 1ll * fac[i - 1] * i % P;
iFac[i] = (i == 1 ? 1 : 1ll * iFac[P % i] * (P - P / i) % P);
}
for (int i = iFac[0] = 1; i < M; ++i) {
iFac[i] = 1ll * iFac[i - 1] * iFac[i] % P;
}
scanf("%d%d", &m, &n);
for (int i = 0; i < m; ++i) {
scanf("%d", &a[n + 1][i]);
a[0][i] = i;
a[n + 1][i] += i;
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < m; ++j) {
scanf("%d", &a[i][j]);
a[i][j] += j;
}
}
for (int i = 1; i <= n + 1; ++i) ord[i] = i;
sort(ord + 1, ord + n + 2, cmp);
f[0] = 1;
for (int ti = 1; ti <= n + 1; ++ti) {
int i = ord[ti];
for (int j = 0; j < i; ++j) {
f[i] = (f[i] - 1ll * f[j] * calc(j, i)) % P;
}
}
printf("%d\n", (-(f[n + 1] % P) + P) % P);
return 0;
}
Details
Test #1:
score: 100
Accepted
time: 6ms
memory: 11720kb
Test #2:
score: 0
Accepted
time: 9ms
memory: 11724kb
Test #3:
score: -100
Wrong Answer
time: 6ms
memory: 11628kb