QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#314774#8171. Colaucup-team1447#RE 317ms245360kbC++142.5kb2024-01-26 10:50:032024-01-26 10:50:04

Judging History

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

  • [2024-01-26 10:50:04]
  • 评测
  • 测评结果:RE
  • 用时:317ms
  • 内存:245360kb
  • [2024-01-26 10:50:03]
  • 提交

answer

// what is matter? never mind.
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
//#define int long long
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

#define mod 998244353
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,modint b){return a.x==b.x;}
	friend bool operator !=(modint a,modint b){return a.x!=b.x;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}

vector<modint> fac,ifac,iv;
inline void initC(int n)
{
	if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
	int m=iv.size(); ++n;
	if(m>=n)return;
	iv.resize(n),fac.resize(n),ifac.resize(n);
	For(i,m,n-1){
		iv[i]=iv[mod%i]*(mod-mod/i);
		fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
	}
}
inline modint C(int n,int m){
	if(m<0||n<m)return 0;
	return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
 
#define maxn 2000005
#define inf 0x3f3f3f3f

int n,m;
modint f[maxn];

modint F(int up,int n){
	return C(n+up-1,up-1);
}

signed main()
{
	n=read(),m=read()-1;
	for(int k=0; ;++k){
		int t1=k*(3*k-1)/2;
		int t2=k*(3*k+1)/2;
		modint o=sign(k);
		if(t1<=m) f[t1]+=o;
		if(t2<=m && k!=0) f[t2]+=o;
		if(t1>m&&t2>m)break;
	}
	//For(i,0,m)cout<<f[i].x<<" ";cout<<"\n";
	initC(20000000);
	modint res=0;
	For(i,0,m) if(f[i].x) res+=f[i]*F(n+1,m-i);
	res*=ifac[n];
	cout<<res.x;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 317ms
memory: 245156kb

input:

2 1

output:

499122177

result:

ok "499122177"

Test #2:

score: 0
Accepted
time: 263ms
memory: 245256kb

input:

1 1

output:

1

result:

ok "1"

Test #3:

score: 0
Accepted
time: 273ms
memory: 245360kb

input:

167 91

output:

469117530

result:

ok "469117530"

Test #4:

score: -100
Runtime Error

input:

9806463 8975779

output:


result: