QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203016 | #2482. Storage Problems | DreamOn# | TL | 1ms | 9864kb | C++23 | 1.9kb | 2023-10-06 14:41:22 | 2023-10-06 14:41:22 |
Judging History
answer
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),i##z=(b);i<=i##z;i++)
#define ROF(i,a,b) for(int i=(a),i##z=(b);i>=i##z;i--)
using namespace std;
const int N=int(4e2)+10,mo=167772161;
int a[N],n,K,ans[N][N];
int pre[N][N][N],suf[N][N][N];
template<typename T>T mul(T x,T y){ return 1ll*x*y%mo; }
int mpw(int x,int y){ int r=1; for(;y;x=mul(x,x),y>>=1) if(y&1) r=mul(r,x); return r; }
int inv(int x){ return mpw(x,mo-2); }
int trs[N*3],L;
void prework(){
L=1; while(L<=n*2) L<<=1;
FOR(i,0,L-1) trs[i]=(trs[i>>1]>>1)|((i&1)?L>>1:0);
}
void ntt(int a[N*3],bool op){
int G=3,invG=inv(G);
FOR(i,0,L-1) if(i<trs[i]) swap(a[i],a[trs[i]]);
for(int len=2;len<=L;len<<=1){
int bs=op?mpw(invG,(mo-1)/len):mpw(G,(mo-1)/len);
for(int i=0;i<L;i+=len){
int now=1;
for(int k=i;k<i+(len>>1);k++){
int tmp=mul( now , a[k+(len>>1)] );
a[k+(len>>1)]=(a[k]-tmp+mo)%mo;
a[k]=(a[k]+tmp)%mo;
now=mul( now , bs );
}
}
}
}
void mul(int a[N*3],int b[N*3],int c[N*3]){
ntt(a,0),ntt(b,0);
FOR(i,0,L-1) c[i]=mul(a[i],b[i]);
ntt(c,1); int ppp=inv(L);
FOR(i,0,L-1) c[i]=mul(c[i],ppp);
}
void Add(int &x,int y){ (x+=y,x>=mo?x-=mo:x); }
int main(){
cin>>n>>K; FOR(i,1,n) cin>>a[i];
pre[0][0][0]=1;
FOR(i,1,n) FOR(j,0,i) FOR(k,0,K){
Add(pre[i][j][k],pre[i-1][j][k]);
if(k<a[i]) continue;
Add(pre[i][j][k],pre[i-1][j-1][k-a[i]]);
}
suf[n+1][0][0]=1;
ROF(i,n,1) FOR(j,0,n-i+1) FOR(k,0,K){
Add(suf[i][j][k],suf[i+1][j][k]);
if(k<a[i]) continue;
Add(suf[i][j][k],suf[i+1][j-1][k-a[i]]);
}
static int p[N*3],q[N*3],r[N*3];
prework();
FOR(i,1,n) FOR(k,0,K){
FOR(j,0,L-1) p[j]=q[j]=0;
FOR(j,0,n-1){
p[j]=pre[i-1][j][k];
FOR(dk,0,a[i]-1) if(K-k-dk>=0)
Add(q[j],suf[i+1][j][K-k-dk]);
}
mul(p,q,r);
FOR(j,0,n-1) Add(ans[i][j],r[j]);
}
FOR(i,1,n) FOR(j,1,n-1) cout<<ans[i][j]<<" \n"[j==n-1];
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7840kb
input:
3 2 1 1 2
output:
1 0 1 0 2 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 7892kb
input:
3 3 2 2 1
output:
1 1 1 1 0 0
result:
ok 3 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 7888kb
input:
3 6 6 5 2
output:
2 0 2 0 2 0
result:
ok 3 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 7908kb
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: 0ms
memory: 7820kb
input:
3 6 1 1 5
output:
0 1 0 1 0 1
result:
ok 3 lines
Test #6:
score: 0
Accepted
time: 1ms
memory: 7932kb
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: 7920kb
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: 1ms
memory: 9864kb
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: 1ms
memory: 7872kb
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: 1ms
memory: 7796kb
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: 1ms
memory: 7848kb
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: 1ms
memory: 7860kb
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: 1ms
memory: 7860kb
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: 1ms
memory: 7864kb
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: 1ms
memory: 7948kb
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: 1ms
memory: 7920kb
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: 1ms
memory: 7936kb
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: 1ms
memory: 7936kb
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: 1ms
memory: 7832kb
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: 1ms
memory: 7868kb
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: 1ms
memory: 7884kb
input:
3 9 7 7 5
output:
2 0 2 0 2 0
result:
ok 3 lines
Test #22:
score: 0
Accepted
time: 1ms
memory: 7924kb
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: 1ms
memory: 7868kb
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: 1ms
memory: 7884kb
input:
3 8 6 3 2
output:
1 1 1 1 0 0
result:
ok 3 lines
Test #25:
score: 0
Accepted
time: 0ms
memory: 7812kb
input:
3 6 6 6 4
output:
2 0 2 0 2 0
result:
ok 3 lines
Test #26:
score: 0
Accepted
time: 0ms
memory: 7932kb
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: 7784kb
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: 7912kb
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: 1ms
memory: 7940kb
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: 1ms
memory: 7856kb
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: 1ms
memory: 7996kb
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: 1ms
memory: 7912kb
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 ...