QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#737136 | #2209. Good Game | hhoppitree | AC ✓ | 45ms | 11792kb | C++17 | 2.3kb | 2024-11-12 14:45:06 | 2024-11-12 14:45:11 |
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 < ti; ++j) {
f[i] = (f[i] - 1ll * f[ord[j]] * calc(ord[j], i)) % P;
}
}
printf("%d\n", (-(f[n + 1] % P) + P) % P);
return 0;
}
Details
Test #1:
score: 100
Accepted
time: 8ms
memory: 11628kb
Test #2:
score: 0
Accepted
time: 6ms
memory: 11712kb
Test #3:
score: 0
Accepted
time: 8ms
memory: 11732kb
Test #4:
score: 0
Accepted
time: 14ms
memory: 11772kb
Test #5:
score: 0
Accepted
time: 15ms
memory: 11652kb
Test #6:
score: 0
Accepted
time: 20ms
memory: 11720kb
Test #7:
score: 0
Accepted
time: 4ms
memory: 11732kb
Test #8:
score: 0
Accepted
time: 18ms
memory: 11720kb
Test #9:
score: 0
Accepted
time: 22ms
memory: 11720kb
Test #10:
score: 0
Accepted
time: 9ms
memory: 11708kb
Test #11:
score: 0
Accepted
time: 20ms
memory: 11772kb
Test #12:
score: 0
Accepted
time: 11ms
memory: 11672kb
Test #13:
score: 0
Accepted
time: 15ms
memory: 11720kb
Test #14:
score: 0
Accepted
time: 16ms
memory: 11740kb
Test #15:
score: 0
Accepted
time: 12ms
memory: 11648kb
Test #16:
score: 0
Accepted
time: 8ms
memory: 11648kb
Test #17:
score: 0
Accepted
time: 23ms
memory: 11776kb
Test #18:
score: 0
Accepted
time: 17ms
memory: 11684kb
Test #19:
score: 0
Accepted
time: 12ms
memory: 11708kb
Test #20:
score: 0
Accepted
time: 14ms
memory: 11684kb
Test #21:
score: 0
Accepted
time: 21ms
memory: 11784kb
Test #22:
score: 0
Accepted
time: 21ms
memory: 11600kb
Test #23:
score: 0
Accepted
time: 14ms
memory: 11652kb
Test #24:
score: 0
Accepted
time: 26ms
memory: 11772kb
Test #25:
score: 0
Accepted
time: 8ms
memory: 11588kb
Test #26:
score: 0
Accepted
time: 6ms
memory: 11584kb
Test #27:
score: 0
Accepted
time: 17ms
memory: 11600kb
Test #28:
score: 0
Accepted
time: 18ms
memory: 11792kb
Test #29:
score: 0
Accepted
time: 14ms
memory: 11592kb
Test #30:
score: 0
Accepted
time: 9ms
memory: 11704kb
Test #31:
score: 0
Accepted
time: 9ms
memory: 11712kb
Test #32:
score: 0
Accepted
time: 27ms
memory: 11640kb
Test #33:
score: 0
Accepted
time: 13ms
memory: 11592kb
Test #34:
score: 0
Accepted
time: 17ms
memory: 11604kb
Test #35:
score: 0
Accepted
time: 14ms
memory: 11732kb
Test #36:
score: 0
Accepted
time: 13ms
memory: 11592kb
Test #37:
score: 0
Accepted
time: 21ms
memory: 11732kb
Test #38:
score: 0
Accepted
time: 8ms
memory: 11660kb
Test #39:
score: 0
Accepted
time: 29ms
memory: 11712kb
Test #40:
score: 0
Accepted
time: 13ms
memory: 11784kb
Test #41:
score: 0
Accepted
time: 13ms
memory: 11768kb
Test #42:
score: 0
Accepted
time: 20ms
memory: 11732kb
Test #43:
score: 0
Accepted
time: 7ms
memory: 11736kb
Test #44:
score: 0
Accepted
time: 16ms
memory: 11716kb
Test #45:
score: 0
Accepted
time: 15ms
memory: 11672kb
Test #46:
score: 0
Accepted
time: 18ms
memory: 11708kb
Test #47:
score: 0
Accepted
time: 11ms
memory: 11768kb
Test #48:
score: 0
Accepted
time: 18ms
memory: 11648kb
Test #49:
score: 0
Accepted
time: 13ms
memory: 11784kb
Test #50:
score: 0
Accepted
time: 12ms
memory: 11772kb
Test #51:
score: 0
Accepted
time: 12ms
memory: 11704kb
Test #52:
score: 0
Accepted
time: 12ms
memory: 11648kb
Test #53:
score: 0
Accepted
time: 12ms
memory: 11728kb
Test #54:
score: 0
Accepted
time: 9ms
memory: 11732kb
Test #55:
score: 0
Accepted
time: 10ms
memory: 11684kb
Test #56:
score: 0
Accepted
time: 10ms
memory: 11780kb
Test #57:
score: 0
Accepted
time: 28ms
memory: 11736kb
Test #58:
score: 0
Accepted
time: 8ms
memory: 11596kb
Test #59:
score: 0
Accepted
time: 13ms
memory: 11584kb
Test #60:
score: 0
Accepted
time: 12ms
memory: 11708kb
Test #61:
score: 0
Accepted
time: 13ms
memory: 11644kb
Test #62:
score: 0
Accepted
time: 10ms
memory: 11648kb
Test #63:
score: 0
Accepted
time: 18ms
memory: 11636kb
Test #64:
score: 0
Accepted
time: 9ms
memory: 11668kb
Test #65:
score: 0
Accepted
time: 12ms
memory: 11712kb
Test #66:
score: 0
Accepted
time: 13ms
memory: 11728kb
Test #67:
score: 0
Accepted
time: 14ms
memory: 11732kb
Test #68:
score: 0
Accepted
time: 20ms
memory: 11740kb
Test #69:
score: 0
Accepted
time: 29ms
memory: 11732kb
Test #70:
score: 0
Accepted
time: 21ms
memory: 11780kb
Test #71:
score: 0
Accepted
time: 9ms
memory: 11588kb
Test #72:
score: 0
Accepted
time: 24ms
memory: 11780kb
Test #73:
score: 0
Accepted
time: 27ms
memory: 11788kb
Test #74:
score: 0
Accepted
time: 19ms
memory: 11676kb
Test #75:
score: 0
Accepted
time: 12ms
memory: 11716kb
Test #76:
score: 0
Accepted
time: 18ms
memory: 11728kb
Test #77:
score: 0
Accepted
time: 12ms
memory: 11664kb
Test #78:
score: 0
Accepted
time: 13ms
memory: 11724kb
Test #79:
score: 0
Accepted
time: 8ms
memory: 11588kb
Test #80:
score: 0
Accepted
time: 14ms
memory: 11720kb
Test #81:
score: 0
Accepted
time: 13ms
memory: 11712kb
Test #82:
score: 0
Accepted
time: 8ms
memory: 11724kb
Test #83:
score: 0
Accepted
time: 14ms
memory: 11780kb
Test #84:
score: 0
Accepted
time: 14ms
memory: 11716kb
Test #85:
score: 0
Accepted
time: 15ms
memory: 11668kb
Test #86:
score: 0
Accepted
time: 12ms
memory: 11732kb
Test #87:
score: 0
Accepted
time: 13ms
memory: 11744kb
Test #88:
score: 0
Accepted
time: 36ms
memory: 11780kb
Test #89:
score: 0
Accepted
time: 36ms
memory: 11640kb
Test #90:
score: 0
Accepted
time: 36ms
memory: 11656kb
Test #91:
score: 0
Accepted
time: 42ms
memory: 11780kb
Test #92:
score: 0
Accepted
time: 35ms
memory: 11744kb
Test #93:
score: 0
Accepted
time: 38ms
memory: 11728kb
Test #94:
score: 0
Accepted
time: 40ms
memory: 11780kb
Test #95:
score: 0
Accepted
time: 36ms
memory: 11608kb
Test #96:
score: 0
Accepted
time: 37ms
memory: 11740kb
Test #97:
score: 0
Accepted
time: 43ms
memory: 11660kb
Test #98:
score: 0
Accepted
time: 40ms
memory: 11780kb
Test #99:
score: 0
Accepted
time: 40ms
memory: 11736kb
Test #100:
score: 0
Accepted
time: 39ms
memory: 11720kb
Test #101:
score: 0
Accepted
time: 38ms
memory: 11604kb
Test #102:
score: 0
Accepted
time: 34ms
memory: 11656kb
Test #103:
score: 0
Accepted
time: 35ms
memory: 11640kb
Test #104:
score: 0
Accepted
time: 33ms
memory: 11792kb
Test #105:
score: 0
Accepted
time: 45ms
memory: 11736kb