QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#461657#1284. Partition NumberZZZAC ✓282ms5624kbC++231.1kb2024-07-02 21:39:302024-07-02 21:39:34

Judging History

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

  • [2024-07-02 21:39:34]
  • 评测
  • 测评结果:AC
  • 用时:282ms
  • 内存:5624kb
  • [2024-07-02 21:39:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
void modadd(int &x, int v) {
    x += v;
    if (x >= mod) x -= mod;
}
void modsub(int &x, int v) {
    x -= v;
    if (x < 0) x += mod;
}
vector<int> partition_number(int n) {
    vector<int> ans(n + 1), tmp(n + 1);
    const int b = sqrt(n);
    ans[0] = tmp[0] = 1;
    for (int i = 1; i <= b; i++) {
        for (int rep = 0; rep < 2; rep++) {
            for (int j = i; j <= n - i * i; j++)
                modadd(tmp[j], tmp[j - i]);
		}
        for (int j = i * i; j <= n; j++)
            modadd(ans[j], tmp[j - i * i]);
    }
    return ans;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    auto P = partition_number(3e5);
    int T;
    cin >> T;
    while (T--) {
        int n, m;
        cin >> n >> m;
        vector<int> p(P.begin(), P.begin() + m + 1);
        for (int it = 0; it < n; it++) {
            int a;
            cin >> a;
            for (int j = m; j >= a; j--)
                modsub(p[j], p[j - a]);
        }
        cout << p[m] << '\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 208ms
memory: 5420kb

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: 206ms
memory: 5424kb

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: 217ms
memory: 5336kb

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: 221ms
memory: 5540kb

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: 252ms
memory: 5456kb

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: 282ms
memory: 5452kb

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: 231ms
memory: 5528kb

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: 202ms
memory: 5444kb

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: 225ms
memory: 5620kb

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: 240ms
memory: 5452kb

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: 227ms
memory: 5556kb

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: 226ms
memory: 5624kb

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: 214ms
memory: 5476kb

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: 242ms
memory: 5368kb

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: 244ms
memory: 5404kb

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: 241ms
memory: 5400kb

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: 244ms
memory: 5452kb

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"