結果

問題 No.2406 Difference of Coordinate Squared
ユーザー 👑 kmjpkmjp
提出日時 2023-08-05 00:20:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,842 bytes
コンパイル時間 2,626 ms
コンパイル使用メモリ 203,940 KB
実行使用メモリ 122,236 KB
最終ジャッジ日時 2024-04-22 22:43:27
合計ジャッジ時間 19,358 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
59,812 KB
testcase_01 AC 550 ms
122,172 KB
testcase_02 AC 565 ms
122,236 KB
testcase_03 RE -
testcase_04 AC 788 ms
122,232 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 383 ms
88,248 KB
testcase_07 AC 272 ms
82,604 KB
testcase_08 AC 294 ms
45,056 KB
testcase_09 AC 982 ms
103,440 KB
testcase_10 AC 690 ms
117,668 KB
testcase_11 AC 326 ms
51,968 KB
testcase_12 AC 364 ms
56,704 KB
testcase_13 AC 1,194 ms
110,632 KB
testcase_14 AC 602 ms
114,524 KB
testcase_15 AC 644 ms
120,572 KB
testcase_16 AC 485 ms
96,808 KB
testcase_17 AC 130 ms
59,700 KB
testcase_18 RE -
testcase_19 AC 363 ms
58,240 KB
testcase_20 AC 730 ms
118,136 KB
testcase_21 AC 356 ms
93,156 KB
testcase_22 RE -
testcase_23 AC 954 ms
121,044 KB
testcase_24 AC 303 ms
74,380 KB
testcase_25 RE -
testcase_26 AC 135 ms
59,708 KB
testcase_27 RE -
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 142 ms
59,800 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 137 ms
59,848 KB
testcase_32 AC 148 ms
59,684 KB
testcase_33 AC 135 ms
59,860 KB
testcase_34 AC 139 ms
59,808 KB
testcase_35 AC 133 ms
59,740 KB
testcase_36 AC 142 ms
59,816 KB
testcase_37 AC 141 ms
59,888 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 RE -
testcase_40 AC 149 ms
59,696 KB
testcase_41 AC 2 ms
6,940 KB
testcase_42 RE -
testcase_43 AC 2 ms
6,944 KB
testcase_44 AC 2 ms
6,944 KB
testcase_45 AC 138 ms
59,696 KB
testcase_46 AC 154 ms
59,692 KB
testcase_47 AC 141 ms
59,728 KB
testcase_48 RE -
testcase_49 AC 143 ms
59,752 KB
testcase_50 AC 2 ms
6,944 KB
testcase_51 AC 136 ms
59,604 KB
testcase_52 AC 141 ms
59,828 KB
testcase_53 AC 133 ms
59,640 KB
testcase_54 AC 152 ms
59,816 KB
testcase_55 AC 1 ms
6,944 KB
testcase_56 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#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 FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

ll N,M;
ll mo=998244353;
ll comb(ll N_, ll C_) {
	const int NUM_=2400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	M=abs(M);
	map<ll,ll> C;
	FOR(i,N+1) C[M+(1LL*i*i)]=i;
	
	
	ll ret=0;
	if(M==0) {
		assert(0);
	}
	else {
		for(x=0;x<=N;x++) if(C.count(1LL*x*x)) {
			ll X=x;
			ll Y=C[1LL*x*x];
			for(int px=x;px<=N;px++) {
				int mx=px-x;
				if((N-(px+mx+Y))%2) continue;
				int py=Y+(N-(px+mx+Y))/2;
				int my=N-px-py-mx;
				
				if(mx<0||py<Y||my<0) continue;
				ll a=comb(N,px+mx)*comb(px+mx,px)%mo*comb(py+my,my)%mo;
				if(px!=mx) a=a*2%mo;
				if(py!=my) a=a*2%mo;
				(ret+=a)%=mo;
			}
		}
	}
	ll a=(mo+1)/2;
	a=a*a%mo;
	FOR(i,N) ret=ret*a%mo;
	cout<<ret<<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