QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#37059#1284. Partition NumberNaCly_FishWA 902ms20152kbC++1.5kb2022-06-30 10:03:392022-06-30 10:03:42

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-30 10:03:42]
  • 评测
  • 测评结果:WA
  • 用时:902ms
  • 内存:20152kb
  • [2022-06-30 10:03:39]
  • 提交

answer

#pragma GCC optimize (2)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#define N 650003
#define ll long long
#define reg register
#define p 1000000007
#define pi 3.141592653589793
using namespace std;

inline void read(int &x){
    x = 0;
    char c = getchar();
    while(c<'0'||c>'9') c = getchar();
    while(c>='0'&&c<='9'){
        x = (x<<3)+(x<<1)+(c^48);
        c = getchar();
    }
}

struct coef{
    int v,t;
    inline coef(int _v=0,int _t=0):v(_v),t(_t){}
    inline bool operator < (const coef& rhs) const{
        return t < rhs.t;
    }
};

inline int omega(int x){
    return (3ll*x*x-x)>>1;
}

int T,n,m,tmp,len,sum,ans;
int f[N],g[N],a[N];
coef h[N],_h[N];
ll sup,t;

int main(){
    scanf("%d",&T);
    m = 300000;
    for(int i=1;omega(i)<=m;i++){
        g[t++] = omega(i);
        g[t++] = omega(-i);
    }
    f[0] = 1;
    for(int i=1;i<=m;i++){
        for(int j=0;j<t&&g[j]<=i;j++)
            f[i] = (f[i]+(ll)(((j>>1)&1)?-1:1)*f[i-g[j]])%p;
    }
    while(T--){
        scanf("%d%d",&n,&m);
        sup = (ll)m*(m+1)>>1;
        t = 0;
        for(int i=1;i<=n;++i){
            scanf("%d",&a[i]);
            t += a[i];
        }
        if(sup-t<m){
            puts("0");
            continue;
        }
        memcpy(g,f,(m+1)<<2);
        for(int i=1;i<=n;++i)
            for(int j=m;j>=a[i];--j)
                g[j] = (g[j]-g[j-a[i]])%p;
        printf("%d\n",(g[m]+p)%p);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 809ms
memory: 17288kb

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: 807ms
memory: 17360kb

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: 798ms
memory: 17860kb

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: 827ms
memory: 19944kb

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: 880ms
memory: 20148kb

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: 902ms
memory: 18252kb

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: 838ms
memory: 20152kb

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: -100
Wrong Answer
time: 799ms
memory: 20124kb

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
0
0
18
215
1
48
4464
0
34
8213

result:

wrong answer 9th words differ - expected: '5', found: '0'