QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#55434#1284. Partition NumberCrysfly#AC ✓155ms9972kbC++112.6kb2022-10-13 19:06:502022-10-13 19:06:52

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-13 19:06:52]
  • 评测
  • 测评结果:AC
  • 用时:155ms
  • 内存:9972kb
  • [2022-10-13 19:06:50]
  • 提交

answer

// what is matter? never mind. 
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
//#define int long long 
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	if(f)x=-x;return x;
}

// modint
#define mod 1000000007
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,int b){return a.x==b;}
	friend bool operator !=(modint a,int b){return a.x!=b;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}

vector<modint> fac,ifac,iv;
inline void initC(int n)
{
	if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
	int m=iv.size(); ++n;
	if(m>=n)return;
	iv.resize(n),fac.resize(n),ifac.resize(n);
	For(i,m,n-1){
		iv[i]=iv[mod%i]*(mod-mod/i);
		fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
	}
}
inline modint C(int n,int m){
	if(m<0||n<m)return 0;
	return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 1000005
#define inf 0x3f3f3f3f

modint dp[300005],tmp[300005];

void init(int n){
	int B=sqrt(n);
	dp[0]=tmp[0]=1;
	For(i,1,B){
		For(_,0,1) For(j,i,n-i*i) tmp[j]+=tmp[j-i];
		For(j,i*i,n) dp[j]+=tmp[j-i*i];
	}
}

modint f[maxn];
void work()
{
	int n=read(),m=read();
	For(i,0,m) f[i]=dp[i];
	For(_,1,n){
		int x=read();
		Rep(i,m,x) f[i]-=f[i-x];
	}
	cout<<f[m].x<<'\n';
}

signed main()
{
//	freopen("my.out","w",stdout);
	init(300005);
	int T=read();
	while(T--)work();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 94ms
memory: 9828kb

input:

5
1 4
1
1 4
2
1 4
3
3 4
1 2 3
4 4
1 2 3 4

output:

2
3
4
1
0

result:

ok 5 tokens

Test #2:

score: 0
Accepted
time: 117ms
memory: 9900kb

input:

500
1 2921
832
1 1952
1842
1 1890
1711
1 2710
2136
1 1420
118
1 1427
921
1 1436
1346
1 1099
676
1 1146
75
1 1993
963
1 2819
34
1 1830
19
1 2900
1912
1 1070
993
1 2114
1434
1 2115
457
1 1407
888
1 1374
98
1 1450
555
1 2740
1469
1 2983
490
1 2209
418
1 2698
2671
1 2653
734
1 1707
1674
1 1247
527
1 147...

output:

656513071
370664764
307269426
290963116
49499707
470710
612150225
330845525
873165144
948675759
659641122
968862177
64639712
328389177
408917220
4498768
640121836
656874091
378916100
635314832
495592694
366885137
89776883
143643404
419554963
926186762
98591876
493963833
801434574
773303382
384230433...

result:

ok 500 tokens

Test #3:

score: 0
Accepted
time: 92ms
memory: 9812kb

input:

100
9 1772
834 532 435 1280 1656 258 1125 1428 1081
4 1378
109 959 683 1359
5 1404
343 99 582 1314 1158
5 1732
343 88 1518 383 888
1 1649
809
3 2148
529 398 1274
9 1498
1149 1100 753 1438 1023 781 1382 174 812
5 1974
1672 1049 946 556 1368
3 1841
1126 778 1203
8 2823
1492 1855 59 1955 2160 1733 132 ...

output:

337901251
92194599
724015244
956239082
302019412
406401766
344249249
479624994
755799589
665478883
829882337
870185928
158625521
151656158
153754980
656712357
376024919
799731771
627915771
42105045
764310042
734330711
22153723
616632794
753088730
727367604
240794329
455175449
121526220
549167830
313...

result:

ok 100 tokens

Test #4:

score: 0
Accepted
time: 95ms
memory: 9928kb

input:

92
7 173404
72479 124269 59047 162390 41915 86058 157822
6 255357
53502 142242 153414 74581 119627 19660
5 74545
19781 39026 57871 62987 22406
10 22603
7485 21651 14792 12107 309 1582 13670 20560 22140 12861
8 228146
192438 85598 28998 172527 207673 44756 76564 153872
1 222780
36785
5 36392
15587 12...

output:

971077271
186128421
983025544
906251696
488917807
604520095
230445818
809516917
107613732
594997978
465226262
462486685
358259225
753355429
483189935
885847665
6050158
678761362
190904328
288238280
479830224
184166550
891029081
601945609
531409235
960433320
146210933
142873867
732461029
133621145
91...

result:

ok 92 tokens

Test #5:

score: 0
Accepted
time: 116ms
memory: 9812kb

input:

88
9 300000
135611 236762 111403 45094 270112 9934 88394 59702 195478
6 300000
177214 29569 156343 164545 299884 16572
9 300000
137009 10532 185117 33250 134526 23853 267930 34176 197110
1 300000
234290
4 300000
106300 253787 155324 119624
6 300000
196957 52415 197936 20763 137315 203119
5 300000
13...

output:

626365059
802395293
13233739
589352886
918649805
736863461
366113724
182902560
489742726
783259244
687611335
178008522
849297756
568129485
53244924
976269787
891479246
128552176
39718969
53419326
358454708
812293281
212802038
137663089
308025361
757726170
508196731
408418998
277991516
208307558
8906...

result:

ok 88 tokens

Test #6:

score: 0
Accepted
time: 155ms
memory: 9792kb

input:

500
1 300000
35710
1 300000
260978
1 300000
93491
1 300000
158743
1 300000
219192
1 300000
166729
1 300000
23630
1 300000
196423
1 300000
35853
1 300000
39777
1 300000
222818
1 300000
189598
1 300000
188523
1 300000
6455
1 300000
237085
1 300000
232602
1 300000
252191
1 300000
26408
1 300000
146540
...

output:

566089083
289308370
24316445
106237706
219409809
674501107
120508003
104675705
285150236
741415784
739843922
606368681
326516431
350704852
710697333
991298360
824437726
405669203
888633877
72711730
313610983
510203572
281518227
756176169
738901649
441130991
630336666
32015153
320983134
218646255
658...

result:

ok 500 tokens

Test #7:

score: 0
Accepted
time: 97ms
memory: 9808kb

input:

18
39 148097
77828 118216 10600 119767 25790 860 61577 130651 25899 53496 34024 147026 135143 145649 108546 62151 112957 27259 24882 22726 135804 6724 111244 42023 72257 138177 85825 129985 58238 57349 105903 42435 116710 111707 132588 97379 101176 76587 116913
50 173949
1761 680 45185 31512 18053 2...

output:

715191714
482729137
364888607
549805043
26978196
754585385
885691959
590589839
783138873
228562215
411372231
362404827
524115787
672928492
901293619
564962196
493650285
918078694

result:

ok 18 tokens

Test #8:

score: 0
Accepted
time: 86ms
memory: 9808kb

input:

18
10 43
23 36 42 39 9 31 28 13 26 16
18 21
15 1 13 8 18 20 19 4 7 2 3 6 10 11 21 12 9 14
12 17
3 7 14 4 10 6 13 16 12 17 8 2
50 50
4 37 46 39 3 10 21 17 13 27 6 2 48 35 49 25 1 44 36 38 19 23 9 40 41 16 34 26 8 31 22 5 30 7 45 42 28 32 43 50 24 12 33 15 18 47 20 29 11 14
50 50
34 41 1 8 20 36 21 44...

output:

42564
1
9
0
0
143
0
1405
5
0
18
215
1
48
4464
0
34
8213

result:

ok 18 tokens

Test #9:

score: 0
Accepted
time: 106ms
memory: 9972kb

input:

15
42 43770
17348 42589 1187 17575 922 14611 10996 38098 32359 13605 29994 18101 29382 28413 23164 26830 1796 40592 15574 5483 23688 41635 20709 499 34695 34806 39572 41553 5583 26388 3499 4652 9584 20628 40616 8841 327 41799 33337 20150 6667 28220
23 273389
235535 90643 40669 38979 77005 208333 227...

output:

173502107
737799863
563863212
735653551
553490678
152281931
928283412
774321534
192763415
105571002
724361022
833576388
73177698
205150831
726038675

result:

ok 15 tokens

Test #10:

score: 0
Accepted
time: 108ms
memory: 9756kb

input:

4
113 289757
138146 135333 183648 105625 262124 152879 187897 240443 49583 203807 236710 64871 191564 256077 62390 211026 272875 210148 275475 274416 240479 47756 69654 22218 257604 139859 208838 239921 97051 253922 221045 217560 172661 275976 4552 215282 97656 183561 271836 239872 25904 165194 2558...

output:

911645549
14056634
876677633
874473058

result:

ok 4 tokens

Test #11:

score: 0
Accepted
time: 101ms
memory: 9932kb

input:

4
192 280344
181527 26698 30860 139345 270419 44758 269981 955 176563 58786 137229 235076 266208 87719 49624 203907 128199 218896 197338 185044 245166 30599 240603 57832 262826 18140 6794 113210 17663 164600 258377 159480 57372 274416 15310 140723 178296 251619 83746 218123 147754 16584 172201 28017...

output:

28694316
974542949
111322837
896296418

result:

ok 4 tokens

Test #12:

score: 0
Accepted
time: 94ms
memory: 9776kb

input:

4
170 168248
17626 158909 129276 154607 128416 46190 120189 81398 81115 167869 105556 163931 117927 59873 59960 58731 38633 166186 142884 127690 120907 96105 14673 76658 124664 108754 94511 166247 123841 122027 101685 64788 17140 26294 161094 108940 79071 83365 129017 43380 63215 150700 151670 11959...

output:

567441075
609765073
36109512
676254947

result:

ok 4 tokens

Test #13:

score: 0
Accepted
time: 98ms
memory: 9884kb

input:

4
183 97446
21290 95128 25376 31101 9873 61711 87988 48897 1485 96392 30043 2247 22769 51068 53330 81730 84433 16359 535 10664 92433 36027 38296 67448 22878 69016 66096 81444 80627 47422 72957 54187 46554 59953 56837 12285 34106 17429 2822 77494 40382 88019 6623 53953 51044 85532 85054 4627 57607 63...

output:

121223914
695247295
911875010
490852118

result:

ok 4 tokens

Test #14:

score: 0
Accepted
time: 110ms
memory: 9900kb

input:

1
500 300000
41264 125404 125000 16117 171225 117530 135210 34744 75460 7001 96629 263936 118816 299598 55357 79924 163716 128231 167667 58261 205005 279159 76715 202332 183514 174882 165511 260501 233419 25150 51852 295531 147064 123110 83188 79918 66717 47591 23256 52643 136249 250261 69649 4805 9...

output:

763230154

result:

ok "763230154"

Test #15:

score: 0
Accepted
time: 111ms
memory: 9752kb

input:

1
500 300000
137189 165758 279656 195266 167079 57729 276139 218452 197774 262944 201002 139731 249566 196806 238425 88145 172002 224586 150747 262031 81984 65987 96734 131383 63611 258912 119588 219029 209147 116720 273371 159837 188973 106346 60936 249169 214112 109238 283313 4138 288230 195429 18...

output:

156542262

result:

ok "156542262"

Test #16:

score: 0
Accepted
time: 106ms
memory: 9792kb

input:

1
500 300000
154109 255014 17381 192408 96290 70717 294003 147128 178316 35660 156725 243410 170345 55633 4080 255155 186769 233991 186399 294356 263352 181642 236507 263005 110896 49462 260397 147299 209970 20854 89522 155634 187205 269296 237522 186663 111279 218722 185342 197066 68126 142564 2414...

output:

551048080

result:

ok "551048080"

Test #17:

score: 0
Accepted
time: 107ms
memory: 9852kb

input:

1
500 300000
289908 103448 252831 133325 247792 107981 288480 61692 77106 115284 207239 166225 43226 64946 66744 25478 91626 263394 197388 297820 135088 275742 240980 73021 197701 289034 147857 145358 86519 175953 230980 203167 127577 249771 221151 187853 168369 170919 8892 218168 77933 202388 17334...

output:

779998906

result:

ok "779998906"