QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#203385 | #2482. Storage Problems | Team_name# | TL | 3ms | 20136kb | C++20 | 3.2kb | 2023-10-06 17:05:46 | 2023-10-06 17:05:47 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define endl '\n'
#define DEBUG_VAR(x) { cerr << "* "#x" = " << x << endl; }
#define DEBUG_FMT(...) { cerr << "* "; fprintf(stderr, __VA_ARGS__); }
using namespace std;
using LL = long long;
const int N = 405;
constexpr LL P = 167772161;
int n, m;
int a[N];
LL f[N][N]; // f[i][j] 表示 i 个东西 有 j 个价值的方案数
// f[i][m+1] 表示 > m
LL suf[N][N][N];
LL g[N][N];
int c[N];
LL ans[N][N]; // ans[i] is ans for a[j] = i
int main()
{
// freopen("1.in", "r", stdin);
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> a[i];
c[a[i]]++;
}
// f[0][0] = 1;
// for(int i = 1; i <= n; i++) {
// for(int j = i; j >= 1; j--) {
// for(int k = m; k > m-a[i]; k--) {
// f[j][m+1] += f[j-1][k];
// f[j][m+1] %= P;
// }
// for(int k = m; k >= a[i]; k--) {
// f[j][k] += f[j-1][k-a[i]];
// f[j][k] %= P;
// }
// }
// }
suf[m+1][0][0] = 1;
for(int i = m, cnt = 0; i >= 1; i--) {
memcpy(suf[i], suf[i+1], sizeof suf[i]);
for(int j = 1; j <= c[i]; j++) {
cnt++; // 目前加入了多少个
for(int k = cnt; k >= 1; k--) {
// for(int r = m; r > m-i; r--) {
// suf[i][k][m+1] += suf[i][k-1][r];
// suf[i][k][m+1] %= P;
// }
for(int r = m; r >= i; r--) {
suf[i][k][r] += suf[i][k-1][r-i];
suf[i][k][r] %= P;
// DEBUG_FMT("suf(%d, %d, %d) = %lld\n", i, k, r, suf[i][k][r]);
// DEBUG_VAR(suf[i][k][r]);
}
}
}
}
for(int i = m; i >= 1; i--) {
for(int j = 0; j <= n; j++) {
for(int k = m-1; k >= 0; k--) {
suf[i][j][k] += suf[i][j][k+1];
suf[i][j][k] %= P;
}
}
}
g[0][0] = 1;
for(int i = 1, cnt = 0; i <= m; i++) {
if(!c[i]) continue;
for(int j = 1; j <= c[i]-1; j++) {
cnt++; // 目前加入了多少个
for(int k = cnt; k >= 1; k--) {
// for(int r = m; r > m-i; r--) {
// g[k][m+1] += g[k-1][r];
// g[k][m+1] %= P;
// }
for(int r = m; r >= i; r--) {
g[k][r] += g[k-1][r-i];
g[k][r] %= P;
}
}
}
// for(int k = 0; k <= n; k++) {
// for(int r = 0; r <= m; r++) {
// DEBUG_FMT("g[%d][%d] = %lld\n", k, r, g[k][r]);
// }
// }
const int maxn = (i <= 20) ? n : min(22, n);
// const int maxn = n;
// 总共几个
for(int j = 1; j <= n-1; j++) {
LL sum = 0;
// 枚举 suf 出几个
for(int k = 0; k <= j && k <= maxn; k++) {
// (j-k)
// 枚举前面出多少
for(int r = 0; r <= m; r++) {
sum += g[j-k][r]*(suf[i+1][k][max(m-i-r+1, 0)]-suf[i+1][k][m-r+1]);
// DEBUG_FMT("(i, j): (%d, %d)\n", i, j);
// DEBUG_VAR(suf[i+1][k][m-i-r+1]-suf[i+1][k][m-r+1]);
// DEBUG_VAR(g[j-k][r]);
sum %= P;
}
}
ans[i][j] = sum;
}
cnt++; // 目前加入了多少个
for(int k = cnt; k >= 1; k--) {
for(int r = m; r > m-i; r--) {
g[k][m+1] += g[k-1][r];
g[k][m+1] %= P;
}
for(int r = m; r >= i; r--) {
g[k][r] += g[k-1][r-i];
g[k][r] %= P;
}
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n-1; j++) {
cout << ans[a[i]][j] << " ";
}
cout << endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9888kb
input:
3 2 1 1 2
output:
1 0 1 0 2 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 9788kb
input:
3 3 2 2 1
output:
1 1 1 1 0 0
result:
ok 3 lines
Test #3:
score: 0
Accepted
time: 2ms
memory: 13960kb
input:
3 6 6 5 2
output:
2 0 2 0 2 0
result:
ok 3 lines
Test #4:
score: 0
Accepted
time: 2ms
memory: 14000kb
input:
4 5 3 4 2 5
output:
2 0 0 3 1 0 2 0 0 3 1 0
result:
ok 4 lines
Test #5:
score: 0
Accepted
time: 2ms
memory: 11888kb
input:
3 6 1 1 5
output:
0 1 0 1 0 1
result:
ok 3 lines
Test #6:
score: 0
Accepted
time: 2ms
memory: 14000kb
input:
7 5 5 5 2 4 4 5 3
output:
6 1 0 0 0 0 6 1 0 0 0 0 5 0 0 0 0 0 6 1 0 0 0 0 6 1 0 0 0 0 6 1 0 0 0 0 5 0 0 0 0 0
result:
ok 7 lines
Test #7:
score: 0
Accepted
time: 0ms
memory: 11896kb
input:
4 6 2 4 4 5
output:
1 0 0 2 1 0 2 1 0 3 2 0
result:
ok 4 lines
Test #8:
score: 0
Accepted
time: 3ms
memory: 15992kb
input:
4 9 2 5 5 5
output:
0 0 0 2 2 0 2 2 0 2 2 0
result:
ok 4 lines
Test #9:
score: 0
Accepted
time: 0ms
memory: 13944kb
input:
4 5 5 3 1 3
output:
3 2 0 2 1 0 1 0 0 2 1 0
result:
ok 4 lines
Test #10:
score: 0
Accepted
time: 2ms
memory: 15996kb
input:
5 6 3 2 5 5 1
output:
2 2 0 0 2 2 0 0 3 4 1 0 3 4 1 0 0 0 0 0
result:
ok 5 lines
Test #11:
score: 0
Accepted
time: 0ms
memory: 13936kb
input:
4 5 5 2 1 5
output:
3 1 0 2 0 0 2 0 0 3 1 0
result:
ok 4 lines
Test #12:
score: 0
Accepted
time: 2ms
memory: 13868kb
input:
7 5 3 1 2 4 3 1 3
output:
3 10 3 0 0 0 0 4 0 0 0 0 1 8 3 0 0 0 4 12 4 0 0 0 3 10 3 0 0 0 0 4 0 0 0 0 3 10 3 0 0 0
result:
ok 7 lines
Test #13:
score: 0
Accepted
time: 0ms
memory: 18048kb
input:
6 8 8 1 8 4 2 1
output:
5 6 4 1 0 2 0 0 0 0 5 6 4 1 0 2 0 0 0 0 2 0 0 0 0 2 0 0 0 0
result:
ok 6 lines
Test #14:
score: 0
Accepted
time: 0ms
memory: 15968kb
input:
5 6 6 5 5 5 6
output:
4 0 0 0 4 0 0 0 4 0 0 0 4 0 0 0 4 0 0 0
result:
ok 5 lines
Test #15:
score: 0
Accepted
time: 0ms
memory: 18032kb
input:
6 8 5 3 8 5 8 4
output:
4 2 0 0 0 2 0 0 0 0 5 3 0 0 0 4 2 0 0 0 5 3 0 0 0 4 2 0 0 0
result:
ok 6 lines
Test #16:
score: 0
Accepted
time: 2ms
memory: 18028kb
input:
4 8 3 4 7 4
output:
1 1 0 1 1 0 3 3 0 1 1 0
result:
ok 4 lines
Test #17:
score: 0
Accepted
time: 0ms
memory: 13860kb
input:
7 5 2 5 5 1 3 3 1
output:
2 4 2 0 0 0 6 9 3 0 0 0 6 9 3 0 0 0 2 2 0 0 0 0 3 5 2 0 0 0 3 5 2 0 0 0 2 2 0 0 0 0
result:
ok 7 lines
Test #18:
score: 0
Accepted
time: 0ms
memory: 20136kb
input:
4 9 3 7 5 3
output:
1 1 0 3 3 0 1 1 0 1 1 0
result:
ok 4 lines
Test #19:
score: 0
Accepted
time: 3ms
memory: 20080kb
input:
6 9 2 7 6 9 4 9
output:
2 0 0 0 0 4 2 0 0 0 4 2 0 0 0 5 3 0 0 0 4 2 0 0 0 5 3 0 0 0
result:
ok 6 lines
Test #20:
score: 0
Accepted
time: 2ms
memory: 18092kb
input:
7 7 2 1 2 4 7 7 6
output:
3 2 1 0 0 0 2 0 0 0 0 0 3 2 1 0 0 0 3 2 1 0 0 0 6 7 3 0 0 0 6 7 3 0 0 0 5 6 3 0 0 0
result:
ok 7 lines
Test #21:
score: 0
Accepted
time: 0ms
memory: 20128kb
input:
3 9 7 7 5
output:
2 0 2 0 2 0
result:
ok 3 lines
Test #22:
score: 0
Accepted
time: 2ms
memory: 16000kb
input:
5 8 8 8 7 2 7
output:
4 0 0 0 4 0 0 0 4 0 0 0 4 0 0 0 4 0 0 0
result:
ok 5 lines
Test #23:
score: 0
Accepted
time: 3ms
memory: 20132kb
input:
5 9 5 3 6 9 8
output:
3 1 0 0 2 0 0 0 3 1 0 0 4 2 0 0 4 2 0 0
result:
ok 5 lines
Test #24:
score: 0
Accepted
time: 0ms
memory: 16012kb
input:
3 8 6 3 2
output:
1 1 1 1 0 0
result:
ok 3 lines
Test #25:
score: 0
Accepted
time: 2ms
memory: 15996kb
input:
3 6 6 6 4
output:
2 0 2 0 2 0
result:
ok 3 lines
Test #26:
score: 0
Accepted
time: 2ms
memory: 13932kb
input:
7 5 4 3 3 5 5 1 4
output:
5 3 0 0 0 0 5 3 0 0 0 0 5 3 0 0 0 0 6 4 0 0 0 0 6 4 0 0 0 0 2 0 0 0 0 0 5 3 0 0 0 0
result:
ok 7 lines
Test #27:
score: 0
Accepted
time: 0ms
memory: 17964kb
input:
4 8 6 4 1 5
output:
2 2 0 2 2 0 0 0 0 2 2 0
result:
ok 4 lines
Test #28:
score: 0
Accepted
time: 0ms
memory: 16004kb
input:
6 8 5 6 3 8 7 6
output:
4 0 0 0 0 5 1 0 0 0 4 0 0 0 0 5 1 0 0 0 5 1 0 0 0 5 1 0 0 0
result:
ok 6 lines
Test #29:
score: 0
Accepted
time: 0ms
memory: 15996kb
input:
5 7 7 3 3 1 2
output:
4 6 3 0 1 1 1 0 1 1 1 0 1 0 0 0 1 1 1 0
result:
ok 5 lines
Test #30:
score: 0
Accepted
time: 2ms
memory: 18024kb
input:
7 8 4 7 1 5 2 5 4
output:
3 7 3 0 0 0 5 10 4 0 0 0 0 1 0 0 0 0 4 8 3 0 0 0 1 2 0 0 0 0 4 8 3 0 0 0 3 7 3 0 0 0
result:
ok 7 lines
Test #31:
score: 0
Accepted
time: 2ms
memory: 13948kb
input:
7 5 4 5 3 4 4 1 4
output:
5 4 0 0 0 0 6 5 0 0 0 0 5 4 0 0 0 0 5 4 0 0 0 0 5 4 0 0 0 0 1 0 0 0 0 0 5 4 0 0 0 0
result:
ok 7 lines
Test #32:
score: 0
Accepted
time: 0ms
memory: 17956kb
input:
4 8 3 8 5 8
output:
2 0 0 3 1 0 2 0 0 3 1 0
result:
ok 4 lines
Test #33:
score: -100
Time Limit Exceeded
input:
400 400 131 13 2 91 164 99 7 102 253 22 16 11 2 92 60 113 15 40 23 89 198 4 15 51 93 34 51 19 3 53 15 125 65 22 22 13 111 122 400 39 27 11 119 336 30 63 139 99 162 104 34 26 1 49 152 60 14 92 73 400 24 43 14 84 32 82 65 336 27 27 36 153 3 135 30 242 11 25 29 78 79 32 9 42 80 72 207 206 75 50 50 117 ...