結果

問題 No.1062 素敵なスコア
ユーザー 👑 kmjpkmjp
提出日時 2020-05-23 00:35:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 2,238 bytes
コンパイル時間 2,477 ms
コンパイル使用メモリ 203,468 KB
実行使用メモリ 8,852 KB
最終ジャッジ日時 2024-04-15 20:30:43
合計ジャッジ時間 4,580 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,248 KB
testcase_01 AC 4 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 5 ms
5,376 KB
testcase_18 AC 40 ms
6,688 KB
testcase_19 AC 82 ms
8,620 KB
testcase_20 AC 45 ms
6,932 KB
testcase_21 AC 45 ms
6,960 KB
testcase_22 AC 83 ms
8,688 KB
testcase_23 AC 44 ms
6,920 KB
testcase_24 AC 24 ms
5,868 KB
testcase_25 AC 41 ms
6,704 KB
testcase_26 AC 45 ms
6,944 KB
testcase_27 AC 21 ms
6,016 KB
testcase_28 AC 81 ms
8,852 KB
testcase_29 AC 24 ms
6,016 KB
testcase_30 AC 83 ms
8,800 KB
testcase_31 AC 87 ms
8,716 KB
testcase_32 AC 4 ms
5,376 KB
testcase_33 AC 87 ms
8,764 KB
testcase_34 AC 87 ms
8,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N,A1,A2;
const ll mo=998244353;
ll fact[202020];

ll modpow(ll a, ll n = mo-2) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}
vector<ll> fft(vector<ll> v, bool rev=false) {
	int n=v.size(),i,j,m;
	
	for(i=0,j=1;j<n-1;j++) {
		for(int k=n>>1;k>(i^=k);k>>=1);
		if(i>j) swap(v[i],v[j]);
	}
	for(int m=2; m<=n; m*=2) {
		ll wn=modpow(5,(mo-1)/m);
		if(rev) wn=modpow(wn);
		for(i=0;i<n;i+=m) {
			ll w=1;
			for(int j1=i,j2=i+m/2;j2<i+m;j1++,j2++) {
				ll t1=v[j1],t2=w*v[j2]%mo;
				v[j1]=t1+t2;
				v[j2]=t1+mo-t2;
				while(v[j1]>=mo) v[j1]-=mo;
				while(v[j2]>=mo) v[j2]-=mo;
				w=w*wn%mo;
			}
		}
	}
	if(rev) {
		ll rv = modpow(n);
		FOR(i,n) v[i]=v[i]*rv%mo;
	}
	return v;
}

vector<ll> MultPoly(vector<ll> P,vector<ll> Q,bool resize=false) {
	if(resize) {
		int maxind=0,pi=0,qi=0,i;
		int s=2;
		FOR(i,P.size()) if(norm(P[i])) pi=i;
		FOR(i,Q.size()) if(norm(Q[i])) qi=i;
		maxind=pi+qi+1;
		while(s*2<maxind) s*=2;
		P.resize(s*2);Q.resize(s*2);
	}
	P=fft(P), Q=fft(Q);
	for(int i=0;i<P.size();i++) P[i]=P[i]*Q[i]%mo;
	return fft(P,true);
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	fact[0]=1;
	for(i=1;i<=202010;i++) fact[i]=fact[i-1]*(i)%mo;
	
	cin>>N>>A1>>A2;
	if(A2<A1) swap(A1,A2);
	ll X=A1;
	ll Y=A2-A1;
	ll Z=N-A2;
	ll ret=(X*X+Y*Y+Z*Z)%mo*fact[N-1]%mo;
	vector<ll> P,Q;
	FOR(i,X) P.push_back(modpow(fact[X-i-1]*fact[i]%mo)*fact[X]%mo);
	FOR(i,Z) Q.push_back(modpow(fact[Z-i-1]*fact[i]%mo)*fact[Z]%mo);
	P=MultPoly(P,Q,1);
	
	FOR(i,X+Z-1) {
		ret+=fact[i]*fact[N-i-2]%mo*2*P[i]%mo;
	}
	
	
	
	cout<<ret%mo<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0