c++ or python WA30pts求看
查看原帖
c++ or python WA30pts求看
443675
紊莫turtle楼主2024/1/4 21:09
// Problem: P3223 [HNOI2012] 排队
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P3223
// Memory Limit: 128 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//@紊莫
#include <bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define dF(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void write(int x){if(x<0)x = ~x + 1, putchar('-');if (x > 9) write(x / 10);putchar(x % 10 + '0');}
inline void writeln(int x){write(x);putchar('\n');}
inline void writesp(int x){write(x);putchar(' ');}
inline int lowbit(int x) {return x&(-x);}
typedef long long ll;
typedef pair<int,int> Pair;
const int N=100005,M=(N<<1),inf=0x3f3f3f3f;
int n,m;
struct BigInt{
	int num[N],len,neg=0;
	BigInt(){memset(num,0,sizeof num),len=0;}
	BigInt(string s){
		len=s.length();
		for(int i=1;i<=len;i++)
			num[i]=s[len-i]-'0';
	}
	BigInt(long long s){
		while(s>0)num[++len]=s%10,s/=10;
	}
	void work(int l){
		len=l;
		for(int i=1;i<=l;i++)
			num[i+1]+=num[i]/10,
			num[i]%=10;
		while(len>1&&!num[len])len--;
	}
	void print(){
		for(int i=len;i>=1;i--)
			cout<<num[i];
	} 
	bool operator <(BigInt &x)const{
		if(len!=x.len) return len<x.len;
		for(int i=len;i>=1;i--)
			if(num[i]!=x.num[i])return num[i]<x.num[i];
		return 0;
	}
	BigInt operator + (BigInt &x){
		BigInt res;
		for(int i=1;i<=max(x.len,len);i++){
			res.num[i]+=x.num[i]+num[i];
			res.num[i+1]+=res.num[i]/10;
			res.num[i]%=10;
		}
		res.work(max(x.len,len)+1);
		return res; 
	}
	BigInt operator - (BigInt &x){
		BigInt res;
		for(int i=1;i<=max(x.len,len);i++){
			if(num[i]<x.num[i]){
				num[i]+=10;
				num[i+1]-=1;
			}res.num[i]=num[i]-x.num[i];
		}
		res.work(max(x.len,len)+1);
		return res; 
	}
	BigInt operator * (int &x){
		BigInt res;
		for(int i=1;i<=len;i++){
			res.num[i]+=num[i]*x;
		}res.work(len+2);
		return res;
	}
	
};
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	BigInt x(1),y(2),ans(0);
	F(i,1,n+2) x=x*i;
	F(i,n+4-m,n+3) x=x*i;
	if(n+3>=m) ans=ans+x;
	F(i,1,n+1) y=y*i;
	F(i,n+3-m,n+2) y=y*i;
	if(n+2>=m) ans=ans-y;
	ans.print();
	
    return 0;
}
2024/1/4 21:09
加载中...