QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203309 | #2476. Pizzo Collectors | Team_name# | WA | 1ms | 10196kb | C++20 | 3.0kb | 2023-10-06 16:44:32 | 2023-10-06 16:44:32 |
Judging History
answer
#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 = 1; j <= n; j++) {
for(int k = m; 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;
}
}
}
// 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 <= maxn && k <= j; k++) {
// (j-k)
// 枚举前面出多少
for(int r = 0; r <= m; r++) {
if(m-i-r+1 >= 0) {
sum += g[j-k][r]*(suf[i+1][j][m-i-r+1]-suf[i+1][j][m+1]);
DEBUG_VAR(g[j-k][r]);
DEBUG_VAR(suf[i+1][j][m-i-r+1]-suf[i+1][j][m+1]);
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 10196kb
input:
8 ?A?B?A?C 3 A 1 B 1000 C 100000
output:
result:
wrong answer 1st lines differ - expected: '1301004', found: ''