QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#526588 | #6132. Repair the Artwork | RPChe_ | WA | 3ms | 10088kb | C++14 | 2.2kb | 2024-08-21 18:02:47 | 2024-08-21 18:02:48 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 105, mod = 1e9 + 7;
int n, m, a[N], ans, f[N][2][N * N], b[N], tot;
int qpow(int a, int b = mod - 2) {
int res = 1;
while (b) {
if (b & 1) (res *= a) %= mod;
(a *= a) %= mod, b >>= 1;
}
return res;
}
void add(int &x, int y) {
x += y;
if (abs(x) > (1ll << 60)) x %= mod;
}
void solve() {
for (int i = 0; i <= tot; i++) {
int lim = b[i] * (b[i] - 1) / 2 + b[i];
for (int j = 0; j <= 1; j++) {
for (int k = 0; k <= lim; k++) {
f[i][j][k] = 0;
}
}
}
f[0][0][0] = 1;
for (int i = 0; i < tot; i++) {
int lim = (b[i] - 1) * b[i] / 2 + b[i];
for (int j = 0; j <= 1; j++) {
for (int k = 0; k <= lim; k++) {
if (!f[i][j][k]) continue;
for (int l = i + 1; l <= tot; l++) {
int len = b[l] - b[i] - 1;
if (a[b[l]] == 1) {
add(f[l][j][k + len * (len - 1) / 2 + len], f[i][j][k]);
break;
} else {
add(f[l][!j][k + len * (len - 1) / 2 + len], f[i][j][k]);
}
}
}
}
}
ans = 0;
for (int i = tot; i >= 0; i--) {
int lim = (b[i] - 1) * b[i] / 2 + b[i];
for (int j = 0; j <= 1; j++) {
for (int k = 0; k <= lim; k++) {
int rst = n - b[i];
rst = rst * (rst - 1) / 2 + rst;
if (j & 1) {
add(ans, -f[i][j][k] * qpow(k + rst, m));
} else {
add(ans, f[i][j][k] * qpow(k + rst, m));
}
}
}
if (a[b[i]] == 1) break;
}
ans = (ans % mod + mod) % mod;
}
signed main() {
int T; scanf("%lld", &T);
while (T--) {
scanf("%lld%lld", &n, &m);
tot = 0;
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
if (a[i]) b[++tot] = i;
}
solve();
printf("%lld\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3888kb
input:
3 2 2 2 0 3 2 2 1 0 3 1 2 1 0
output:
8 3 1
result:
ok 3 number(s): "8 3 1"
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 10088kb
input:
100 2 1 0 1 2 1 2 1 2 1 1 1 1 6 2 1 14 2 3 12 2 2 2 6 13 2 2 0 2 0 2 7 14 0 0 0 0 2 2 0 5 8 2 2 0 0 0 5 5 2 2 0 0 0 12 3 0 2 0 2 2 0 1 2 2 2 2 0 7 11 2 2 0 1 0 1 0 4 4 2 1 2 2 7 5 1 1 0 0 1 0 0 2 14 2 1 15 17 2 2 1 2 0 0 0 0 2 0 1 0 0 0 0 15 11 1 1 2 0 1 2 0 0 1 0 2 1 1 1 1 15 18 1 0 1 0 2 2 1 2 0 1...
output:
1 1 0 1 1 175715347 833406719 467966815 458805426 650344 2208 537089254 146 7776 1 703335050 123067364 355668256 487954758 53774922 544070885 436748805 369291507 760487845 513270785 501075264 487417783 464534262 979007529 137956839 143317512 648268264 851188473 702545117 946416372 595191705 35054850...
result:
wrong answer 96th numbers differ - expected: '344490809', found: '926834817'