QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#823197#8428. Partition into TeamsInvincibleWA 0ms3952kbC++232.0kb2024-12-20 20:23:322024-12-20 20:23:33

Judging History

你现在查看的是最新测评结果

  • [2024-12-20 20:23:33]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3952kb
  • [2024-12-20 20:23:32]
  • 提交

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;}

int n,p;
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 get(int x){
	int res=0;
	while(x>=p)res+=x/p,x/=p;
	return res;
}
int fac(int x){
	int res=1;
	rep(i,1,x)if(i%p)res=res*i%p;
	return res;
}

bool Med;
signed main() {
	fprintf(stderr,"%.3lfMb\n",(&Mbe-&Med)/1024./1024.);
	n=read(),p=read();
	int now=1,k=0,ans=0,sum=1,lst=1;
	per(i,n,1){
		if(get(i)+get(n-i)!=get(n))break;
		while(k<min(i-1,n-i)){
			lst=lst*fpow(k+1)%p*(n-i-k)%p;
			sum=(sum+lst)%p;
			k++;
		}
		while(k>min(i-1,n-i)){
			sum=(sum+p-lst)%p;
			lst=lst*k%p*fpow(n-i-k+1)%p;
			k--;
		}
		ans=(ans+now*sum)%p;
		now=now*i%p*fpow(n-i+1)%p;
		sum=(sum*2-lst+p)%p;
		lst=lst*(n-i+1)%p*fpow(n-k-i+1)%p;
	}
	printf("%lld\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3952kb

input:

5 5

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

5 7

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3808kb

input:

789 97

output:

31

result:

wrong answer 1st numbers differ - expected: '53', found: '31'