QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#827780 | #8428. Partition into Teams | Kazemaru | TL | 82ms | 16324kb | C++23 | 916b | 2024-12-23 09:54:51 | 2024-12-23 09:54:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,j,k) for(int i=j;i<=k;++i)
#define g(i,j,k) for(int i=j;i>=k;--i)
int n,m,s,l;
const int N=2e6;
int jc[N],ny[N],p,mo;
inline int ksm(int x,int p=mo-2,int y=1){for(;p;p/=2,x=x*x%mo)if(p&1)y=x*y%mo;return y;}
inline int C(int n,int m){return(n<m||m<0)?0:jc[n]*ny[m]%mo*ny[n-m]%mo;}
inline void ycl(int n){
jc[0]=1;
f(i,1,n)jc[i]=jc[i-1]*i%mo;
ny[n]=ksm(jc[n]);
g(i,n,1)ny[i-1]=ny[i]*i%mo;
}
int C(int a,int b,int c){return C(a,c)*C(b,c)%p;}
int D(int a,int b,int c){return(a||b||c)?D(a/p,b/p,c/p)*C(a%p,b%p,c%p)%p:1;}
int ask(int n,int m,int k){
if(!k)return 0;
int x=0,y=0,z=0,fx=m/p,fy=(m-p+1)/p;
while(k%p)--k,z+=D(n,m-k,k);
f(i,0,p-1)(fx==(m-i)/p?x:y)+=C(n%p,(m-i)%p,i%p);
return(x%p*ask(n/p,fx,k/p)+y%p*ask(n/p,fy,k/p)+z)%p;
}
signed main(){
cin>>n>>p;mo=p;ycl(p-1);
cout<<(ksm(3,n)-ask(n,n,n/2+1)+p)*ksm(2)%p;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5556kb
input:
5 5
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5656kb
input:
5 7
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5552kb
input:
789 97
output:
53
result:
ok 1 number(s): "53"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5548kb
input:
98 23
output:
10
result:
ok 1 number(s): "10"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5596kb
input:
398 7
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 1ms
memory: 5656kb
input:
272 31
output:
18
result:
ok 1 number(s): "18"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5548kb
input:
920 199
output:
39
result:
ok 1 number(s): "39"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5700kb
input:
390 5167
output:
1236
result:
ok 1 number(s): "1236"
Test #9:
score: 0
Accepted
time: 1ms
memory: 5916kb
input:
445 24337
output:
4546
result:
ok 1 number(s): "4546"
Test #10:
score: 0
Accepted
time: 11ms
memory: 14676kb
input:
28 586501
output:
269032
result:
ok 1 number(s): "269032"
Test #11:
score: 0
Accepted
time: 1ms
memory: 5664kb
input:
304 5
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 0ms
memory: 5708kb
input:
7158 41
output:
16
result:
ok 1 number(s): "16"
Test #13:
score: 0
Accepted
time: 0ms
memory: 5556kb
input:
8487 331
output:
148
result:
ok 1 number(s): "148"
Test #14:
score: 0
Accepted
time: 1ms
memory: 5668kb
input:
501 6763
output:
363
result:
ok 1 number(s): "363"
Test #15:
score: 0
Accepted
time: 2ms
memory: 7856kb
input:
3011 61129
output:
49319
result:
ok 1 number(s): "49319"
Test #16:
score: 0
Accepted
time: 10ms
memory: 12092kb
input:
7266 358159
output:
7643
result:
ok 1 number(s): "7643"
Test #17:
score: 0
Accepted
time: 1ms
memory: 5732kb
input:
360860 7
output:
1
result:
ok 1 number(s): "1"
Test #18:
score: 0
Accepted
time: 1ms
memory: 5664kb
input:
154939 19
output:
8
result:
ok 1 number(s): "8"
Test #19:
score: 0
Accepted
time: 1ms
memory: 5660kb
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: 3ms
memory: 6268kb
input:
689332 78079
output:
17208
result:
ok 1 number(s): "17208"
Test #22:
score: 0
Accepted
time: 0ms
memory: 6004kb
input:
287719 34369
output:
15373
result:
ok 1 number(s): "15373"
Test #23:
score: 0
Accepted
time: 1ms
memory: 5592kb
input:
439237583 7
output:
6
result:
ok 1 number(s): "6"
Test #24:
score: 0
Accepted
time: 1ms
memory: 5656kb
input:
319142531 79
output:
21
result:
ok 1 number(s): "21"
Test #25:
score: 0
Accepted
time: 1ms
memory: 5660kb
input:
592330255 631
output:
530
result:
ok 1 number(s): "530"
Test #26:
score: 0
Accepted
time: 1ms
memory: 5736kb
input:
164278463 4517
output:
3038
result:
ok 1 number(s): "3038"
Test #27:
score: 0
Accepted
time: 6ms
memory: 8112kb
input:
753671285 65371
output:
22369
result:
ok 1 number(s): "22369"
Test #28:
score: 0
Accepted
time: 48ms
memory: 16324kb
input:
289665297 663127
output:
168503
result:
ok 1 number(s): "168503"
Test #29:
score: 0
Accepted
time: 5ms
memory: 5660kb
input:
350585676619 7
output:
5
result:
ok 1 number(s): "5"
Test #30:
score: 0
Accepted
time: 1ms
memory: 5660kb
input:
4283693890775 31
output:
1
result:
ok 1 number(s): "1"
Test #31:
score: 0
Accepted
time: 1ms
memory: 5660kb
input:
1234727503131 151
output:
67
result:
ok 1 number(s): "67"
Test #32:
score: 0
Accepted
time: 2ms
memory: 5664kb
input:
9399186742989 1327
output:
678
result:
ok 1 number(s): "678"
Test #33:
score: 0
Accepted
time: 3ms
memory: 5776kb
input:
1409645481800 8719
output:
1939
result:
ok 1 number(s): "1939"
Test #34:
score: 0
Accepted
time: 82ms
memory: 14192kb
input:
3782178721166 552859
output:
458256
result:
ok 1 number(s): "458256"
Test #35:
score: -100
Time Limit Exceeded
input:
827235816874722972 5