QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#827748 | #8428. Partition into Teams | Kazemaru | TL | 12ms | 14564kb | C++14 | 856b | 2024-12-23 09:33:29 | 2024-12-23 09:33:29 |
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],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 D(int a,int b,int c){return(a||b||c)?D(a/mo,b/mo,c/mo)*C(a%mo,b%mo)%mo*C(b%mo,c%mo)%mo:1;}
int E(int a,int b,int c){static int X,Y,Z,W;if(X!=a/mo||Y!=b/mo||Z!=c/mo||!(X+Y+Z))W=D(X=a/mo,Y=b/mo,Z=c/mo);return W*C(a%mo,b%mo)%mo*C(b%mo,c%mo)%mo;}
signed main(){
cin>>n>>mo;ycl(mo-1);
f(i,0,n/2)m=(m+E(n,n-i,i))%mo;
cout<<(ksm(3,n)-m+mo)*ksm(2)%mo;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5596kb
input:
5 5
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5696kb
input:
5 7
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5556kb
input:
789 97
output:
53
result:
ok 1 number(s): "53"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5600kb
input:
98 23
output:
10
result:
ok 1 number(s): "10"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5664kb
input:
398 7
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 0ms
memory: 5664kb
input:
272 31
output:
18
result:
ok 1 number(s): "18"
Test #7:
score: 0
Accepted
time: 0ms
memory: 5608kb
input:
920 199
output:
39
result:
ok 1 number(s): "39"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5704kb
input:
390 5167
output:
1236
result:
ok 1 number(s): "1236"
Test #9:
score: 0
Accepted
time: 1ms
memory: 5844kb
input:
445 24337
output:
4546
result:
ok 1 number(s): "4546"
Test #10:
score: 0
Accepted
time: 6ms
memory: 14564kb
input:
28 586501
output:
269032
result:
ok 1 number(s): "269032"
Test #11:
score: 0
Accepted
time: 1ms
memory: 5728kb
input:
304 5
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 1ms
memory: 5668kb
input:
7158 41
output:
16
result:
ok 1 number(s): "16"
Test #13:
score: 0
Accepted
time: 1ms
memory: 5612kb
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: 6152kb
input:
3011 61129
output:
49319
result:
ok 1 number(s): "49319"
Test #16:
score: 0
Accepted
time: 3ms
memory: 12096kb
input:
7266 358159
output:
7643
result:
ok 1 number(s): "7643"
Test #17:
score: 0
Accepted
time: 10ms
memory: 5592kb
input:
360860 7
output:
1
result:
ok 1 number(s): "1"
Test #18:
score: 0
Accepted
time: 0ms
memory: 5664kb
input:
154939 19
output:
8
result:
ok 1 number(s): "8"
Test #19:
score: 0
Accepted
time: 10ms
memory: 5648kb
input:
813268 47
output:
40
result:
ok 1 number(s): "40"
Test #20:
score: 0
Accepted
time: 12ms
memory: 5564kb
input:
965601 1531
output:
1147
result:
ok 1 number(s): "1147"
Test #21:
score: 0
Accepted
time: 10ms
memory: 8316kb
input:
689332 78079
output:
17208
result:
ok 1 number(s): "17208"
Test #22:
score: 0
Accepted
time: 4ms
memory: 5924kb
input:
287719 34369
output:
15373
result:
ok 1 number(s): "15373"
Test #23:
score: -100
Time Limit Exceeded
input:
439237583 7