QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#827747 | #8428. Partition into Teams | Kazemaru | WA | 1ms | 5700kb | C++14 | 858b | 2024-12-23 09:32:48 | 2024-12-23 09:32:48 |
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)*C(a%mo,b%mo)%mo*C(b%mo,c%mo)%mo;return W;}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5516kb
input:
5 5
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5512kb
input:
5 7
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5700kb
input:
789 97
output:
53
result:
ok 1 number(s): "53"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 5696kb
input:
98 23
output:
4
result:
wrong answer 1st numbers differ - expected: '10', found: '4'