QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203391 | #2482. Storage Problems | Team_name# | WA | 1ms | 11832kb | C++20 | 2.3kb | 2023-10-06 17:09:49 | 2023-10-06 17:09:50 |
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]]++;
}
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 >= i; r--) {
suf[i][k][r] += suf[i][k-1][r-i];
suf[i][k][r] %= P;
}
}
}
}
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 >= i; r--) {
g[k][r] += g[k-1][r-i];
g[k][r] %= P;
}
}
}
const int maxn = n/(i+1);
// 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]);
// sum %= P;
}
}
ans[i][j] = (sum%P+P)%P;
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7860kb
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: 11816kb
input:
3 3 2 2 1
output:
1 1 1 1 0 0
result:
ok 3 lines
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 11832kb
input:
3 6 6 5 2
output:
2 0 1 0 2 0
result:
wrong answer 2nd lines differ - expected: '2 0', found: '1 0 '