QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#823817 | #8428. Partition into Teams | Invincible | WA | 1ms | 6000kb | C++23 | 1.8kb | 2024-12-21 09:58:30 | 2024-12-21 09:58:30 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <ctime>
#include <random>
#include <cassert>
#include <numeric>
#include <cmath>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int, int>
#define fi first
#define se second
#define MP make_pair
#define ep emplace
#define eb emplace_back
#define int long long
#define rep(i, j, k) for (int i = (j); i <= (k); i++)
#define per(i, j, k) for (int i = (j); i >= (k); i--)
typedef double db;
typedef long double ldb;
typedef long long ll;
//typedef __int128 lll;
typedef unsigned long long ull;
typedef unsigned int ui;
using namespace std;
using namespace __gnu_pbds;
bool Mbe;
//char buf[1<<20],*p1,*p2;
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin), p1 == p2) ? 0 : *p1++)
int read() {
int s = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') f ^= (c == '-'), c = getchar();
while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
return f ? s : -s;
}
template<typename T>void chkmax(T&x,const T&y){if(x<y)x=y;}
template<typename T>void chkmin(T&x,const T&y){if(x>y)x=y;}
const int N=1000005;
int n,p,fac[N],ifac[N],ans;
int fpow(int x,int k=p-2){
int res=1;
for(;k;k>>=1){
if(k&1)res=res*x%p;
x=x*x%p;
}
return res;
}
int C(int x,int y){return x<y?0:fac[x]*ifac[y]%p*ifac[x-y]%p;}
int Comb(int x,int y){
if(x<y)return 0;
if(x<p&&y<p)return C(x,y);
return C(x%p,y%p)*Comb(x/p,y/p)%p;
}
bool Med;
signed main() {
fprintf(stderr,"%.3lfMb\n",(&Mbe-&Med)/1024./1024.);
n=read(),p=read();
fac[0]=1;
rep(i,1,p-1)fac[i]=fac[i-1]*i%p;
ifac[p-1]=fpow(fac[p-1]);
per(i,p-1,1)ifac[i-1]=ifac[i]*i%p;
rep(i,0,min(n,p))ans=(ans+Comb(n,i)*Comb(n-i,i))%p;
ans=(fpow(3,n)-ans+p)*fpow(2)%p;
printf("%lld\n",ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 5920kb
input:
5 5
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 6000kb
input:
5 7
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5872kb
input:
789 97
output:
47
result:
wrong answer 1st numbers differ - expected: '53', found: '47'