QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203068 | #2482. Storage Problems | DreamOn# | TL | 1975ms | 483572kb | C++23 | 2.8kb | 2023-10-06 15:11:11 | 2023-10-06 15:11:12 |
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 read() {
int x = 0, f = 1;
char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while('0' <= c && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
int a[N],n,K,ans[N][N];
int pre[N][N][N],suf[N][N][N],psuf[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(int len){
L=1; while(L<=len) L<<=1;
FOR(i,0,L-1) trs[i]=(trs[i>>1]>>1)|((i&1)?L>>1:0);
}
void ntt(int *a,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,int *b,int *c){
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 check(int x){ return x>=mo?x-mo:x; }
int check_len(int *a,int ed){
while(a[ed]==0 && ed>0) ed--;
return ed+1;
}
int main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
int t1=clock();
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]]);
}
ROF(i,n+1,0) FOR(j,0,n-i+1){
psuf[i][j][0]=suf[i][j][0];
FOR(k,1,K) psuf[i][j][k]=check(psuf[i][j][k-1]+suf[i][j][k]);
}
static int p[N*3],q[N*3],r[N*3];
int t2=clock();
cerr<<"?"<<t2-t1<<endl;
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];
q[j]=( psuf[i+1][j][K-k] - (K-k-a[i]<0?0:psuf[i+1][j][K-k-a[i]]) + mo )%mo;
// FOR(dk,0,a[i]-1) if(K-k-dk>=0)
// Add(q[j],suf[i+1][j][K-k-dk]);
}
int len1=check_len(p,n-1);
int len2=check_len(q,n-1);
prework(len1+len2);
FOR(j,n,L-1) p[j]=q[j]=0;
mul(p,q,r);
FOR(j,0,min(n-1,L-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: 0ms
memory: 9960kb
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: 12112kb
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: 9952kb
input:
3 6 6 5 2
output:
2 0 2 0 2 0
result:
ok 3 lines
Test #4:
score: 0
Accepted
time: 1ms
memory: 12028kb
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: 9912kb
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: 12152kb
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: 10076kb
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: 10004kb
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: 11960kb
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: 12152kb
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: 10064kb
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: 0ms
memory: 12160kb
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: 12160kb
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: 12116kb
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: 12184kb
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: 12024kb
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: 14172kb
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: 12016kb
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: 12100kb
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: 14236kb
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: 11996kb
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: 12068kb
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: 10088kb
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: 9956kb
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: 11968kb
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: 14312kb
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: 12028kb
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: 12156kb
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: 11996kb
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: 0ms
memory: 12092kb
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: 0ms
memory: 14196kb
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: 11964kb
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: 0
Accepted
time: 1235ms
memory: 426532kb
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 ...
output:
12 7156 1967080 119136539 34827776 81858977 124110671 61298833 76646242 34519046 58612716 91816388 91296622 115215838 101080005 22736412 57697102 136597697 164696207 77881601 52502636 48239559 5273941 63249857 39054255 89971302 93227129 26823160 48954324 89748626 159996761 118567485 85460269 1421088...
result:
ok 400 lines
Test #34:
score: 0
Accepted
time: 1885ms
memory: 483572kb
input:
400 400 71 8 51 40 26 1 23 12 17 16 6 105 40 16 8 89 46 26 3 8 28 12 22 57 3 212 8 41 7 6 31 39 88 20 46 5 41 44 67 6 31 74 47 15 6 146 41 1 49 36 59 22 8 82 1 59 12 17 8 23 265 87 234 4 54 42 24 24 16 47 14 33 45 21 80 30 106 18 21 54 27 14 164 117 80 46 147 62 11 22 15 19 61 138 5 21 4 26 13 126 2...
output:
0 226 148688 39109205 14071460 26266304 89602608 93660073 141083286 58698150 124017561 32082062 133849745 78356259 124803270 672882 11581122 165069717 95979839 131378115 153627021 144709895 99583163 44924075 63655735 165972788 58851834 28107590 155142094 143410508 57939086 68974736 16851279 14011221...
result:
ok 400 lines
Test #35:
score: 0
Accepted
time: 1956ms
memory: 481292kb
input:
400 400 37 116 32 9 10 1 4 53 14 20 12 1 81 42 1 58 3 40 42 11 5 36 14 54 3 14 49 63 43 1 14 106 91 8 7 7 22 26 2 7 9 31 44 3 16 16 19 19 66 8 79 65 3 7 78 13 35 8 40 80 81 33 42 7 65 10 14 20 16 118 43 28 71 11 16 4 26 8 6 44 11 5 37 19 11 54 50 39 40 39 152 73 40 66 12 38 13 4 14 46 17 1 24 28 21 ...
output:
0 23 15336 4160370 26491142 154722421 135327390 114815970 33176037 29082192 10083129 10120963 80030785 136047703 47588944 45787283 148557792 9193153 9646370 88914373 106408164 7598423 95830598 50394888 88413392 115500759 9952683 13625515 164477864 5722524 158946968 126676708 159627579 1451419 940793...
result:
ok 400 lines
Test #36:
score: 0
Accepted
time: 1975ms
memory: 482064kb
input:
400 400 3 22 63 1 8 48 40 1 22 8 11 14 8 18 31 27 5 3 21 10 27 1 56 7 118 2 14 11 36 5 26 16 28 21 7 11 20 1 26 3 15 21 6 3 91 2 7 25 1 5 36 8 6 25 20 8 20 28 18 6 7 41 26 4 20 24 13 26 15 22 7 45 135 5 3 23 36 26 5 14 1 7 16 1 4 12 21 21 1 30 8 3 48 15 12 7 21 2 37 34 2 31 13 16 25 19 1 2 20 26 33 ...
output:
0 0 0 106 101667 40190401 110157710 130032289 63181298 123972256 49357691 133419871 116294954 57418138 88731217 96307777 167067283 130570571 166854200 112126024 162366791 123716015 62385259 19048379 117577733 59727148 75996212 59883096 3195790 61053318 28593316 33136057 28920849 78426931 119726398 3...
result:
ok 400 lines
Test #37:
score: -100
Time Limit Exceeded
input:
400 400 15 17 22 36 11 6 2 41 10 43 2 4 18 5 10 1 4 2 1 33 1 19 15 14 11 1 28 10 4 26 2 11 10 1 3 1 2 33 8 21 19 4 37 20 4 29 35 9 48 8 4 2 1 5 19 19 7 44 24 62 9 13 24 54 16 4 16 32 6 26 14 1 6 7 1 12 12 6 44 3 13 46 1 1 39 2 25 4 2 6 1 4 8 7 8 44 33 4 15 4 13 25 42 20 1 7 41 10 6 12 5 8 14 3 13 9 ...
output:
0 0 0 0 0 0 331 6287556 120493823 98333620 111830655 17967940 163949081 116732924 143515459 118298745 37133286 65168640 163853660 115535453 53050091 133341510 47684363 102466661 16501458 166316211 150678687 37503935 8120182 15637013 95414118 152899933 52457559 71855697 159636330 79648935 88895190 15...