QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#828034 | #8428. Partition into Teams | hxhhxh | AC ✓ | 66ms | 18120kb | C++14 | 738b | 2024-12-23 12:32:04 | 2024-12-23 12:32:13 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int p,F[5000006],Inv[5000006];
int pw(int x,int y){
int res=1;
for(;y;y>>=1,x=x*x%p) if(y&1) res=res*x%p;
return res;
}
int clc(int x,int y){
if(x<y||y<0) return 0;
return F[x]*Inv[y]%p*Inv[x-y]%p;
}
int C(int x,int y){
if(y==0) return 1;
return C(x/p,y/p)*clc(x%p,y%p)%p;
}
int slv(int n,int m){
int res=0;
for(int i=m/p*p;i<=m;i++) res=(res+C(i*2,i)*C(n,i*2))%p;
if(m>=p){
int t=slv(n/p,m/p-1);
for(int i=0;i*2<p;i++) res=(res+t*C(i*2,i)*C(n%p,i*2))%p;
}
return res;
}
signed main(){
int n;
cin>>n>>p;
for(int i=F[0]=1;i<p;i++) F[i]=F[i-1]*i%p;
Inv[p-1]=p-1;
for(int i=p-1;i;i--) Inv[i-1]=Inv[i]*i%p;
cout<<((pw(3,n)-slv(n,n/2))*((-p)/2)%p+p)%p;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5740kb
input:
5 5
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5736kb
input:
5 7
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5736kb
input:
789 97
output:
53
result:
ok 1 number(s): "53"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5728kb
input:
98 23
output:
10
result:
ok 1 number(s): "10"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5540kb
input:
398 7
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 0ms
memory: 5732kb
input:
272 31
output:
18
result:
ok 1 number(s): "18"
Test #7:
score: 0
Accepted
time: 0ms
memory: 5676kb
input:
920 199
output:
39
result:
ok 1 number(s): "39"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5760kb
input:
390 5167
output:
1236
result:
ok 1 number(s): "1236"
Test #9:
score: 0
Accepted
time: 1ms
memory: 5772kb
input:
445 24337
output:
4546
result:
ok 1 number(s): "4546"
Test #10:
score: 0
Accepted
time: 10ms
memory: 18120kb
input:
28 586501
output:
269032
result:
ok 1 number(s): "269032"
Test #11:
score: 0
Accepted
time: 1ms
memory: 5584kb
input:
304 5
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 0ms
memory: 5660kb
input:
7158 41
output:
16
result:
ok 1 number(s): "16"
Test #13:
score: 0
Accepted
time: 1ms
memory: 5664kb
input:
8487 331
output:
148
result:
ok 1 number(s): "148"
Test #14:
score: 0
Accepted
time: 1ms
memory: 5784kb
input:
501 6763
output:
363
result:
ok 1 number(s): "363"
Test #15:
score: 0
Accepted
time: 2ms
memory: 6056kb
input:
3011 61129
output:
49319
result:
ok 1 number(s): "49319"
Test #16:
score: 0
Accepted
time: 3ms
memory: 11516kb
input:
7266 358159
output:
7643
result:
ok 1 number(s): "7643"
Test #17:
score: 0
Accepted
time: 1ms
memory: 5648kb
input:
360860 7
output:
1
result:
ok 1 number(s): "1"
Test #18:
score: 0
Accepted
time: 1ms
memory: 5732kb
input:
154939 19
output:
8
result:
ok 1 number(s): "8"
Test #19:
score: 0
Accepted
time: 1ms
memory: 5644kb
input:
813268 47
output:
40
result:
ok 1 number(s): "40"
Test #20:
score: 0
Accepted
time: 1ms
memory: 5672kb
input:
965601 1531
output:
1147
result:
ok 1 number(s): "1147"
Test #21:
score: 0
Accepted
time: 5ms
memory: 6272kb
input:
689332 78079
output:
17208
result:
ok 1 number(s): "17208"
Test #22:
score: 0
Accepted
time: 2ms
memory: 5940kb
input:
287719 34369
output:
15373
result:
ok 1 number(s): "15373"
Test #23:
score: 0
Accepted
time: 1ms
memory: 5680kb
input:
439237583 7
output:
6
result:
ok 1 number(s): "6"
Test #24:
score: 0
Accepted
time: 1ms
memory: 5580kb
input:
319142531 79
output:
21
result:
ok 1 number(s): "21"
Test #25:
score: 0
Accepted
time: 0ms
memory: 5544kb
input:
592330255 631
output:
530
result:
ok 1 number(s): "530"
Test #26:
score: 0
Accepted
time: 0ms
memory: 5768kb
input:
164278463 4517
output:
3038
result:
ok 1 number(s): "3038"
Test #27:
score: 0
Accepted
time: 5ms
memory: 6240kb
input:
753671285 65371
output:
22369
result:
ok 1 number(s): "22369"
Test #28:
score: 0
Accepted
time: 39ms
memory: 15156kb
input:
289665297 663127
output:
168503
result:
ok 1 number(s): "168503"
Test #29:
score: 0
Accepted
time: 1ms
memory: 5580kb
input:
350585676619 7
output:
5
result:
ok 1 number(s): "5"
Test #30:
score: 0
Accepted
time: 1ms
memory: 5588kb
input:
4283693890775 31
output:
1
result:
ok 1 number(s): "1"
Test #31:
score: 0
Accepted
time: 1ms
memory: 5648kb
input:
1234727503131 151
output:
67
result:
ok 1 number(s): "67"
Test #32:
score: 0
Accepted
time: 1ms
memory: 5672kb
input:
9399186742989 1327
output:
678
result:
ok 1 number(s): "678"
Test #33:
score: 0
Accepted
time: 2ms
memory: 5612kb
input:
1409645481800 8719
output:
1939
result:
ok 1 number(s): "1939"
Test #34:
score: 0
Accepted
time: 60ms
memory: 14328kb
input:
3782178721166 552859
output:
458256
result:
ok 1 number(s): "458256"
Test #35:
score: 0
Accepted
time: 1ms
memory: 5648kb
input:
827235816874722972 5
output:
2
result:
ok 1 number(s): "2"
Test #36:
score: 0
Accepted
time: 1ms
memory: 5732kb
input:
648249960855836992 61
output:
56
result:
ok 1 number(s): "56"
Test #37:
score: 0
Accepted
time: 1ms
memory: 5684kb
input:
467138518199434341 563
output:
202
result:
ok 1 number(s): "202"
Test #38:
score: 0
Accepted
time: 1ms
memory: 5740kb
input:
616207494477524619 653
output:
95
result:
ok 1 number(s): "95"
Test #39:
score: 0
Accepted
time: 5ms
memory: 5848kb
input:
129689263663821851 34403
output:
30422
result:
ok 1 number(s): "30422"
Test #40:
score: 0
Accepted
time: 66ms
memory: 14864kb
input:
605206340470214709 479971
output:
381982
result:
ok 1 number(s): "381982"