結果

問題 No.2406 Difference of Coordinate Squared
ユーザー shobonvipshobonvip
提出日時 2023-08-04 22:51:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,426 bytes
コンパイル時間 4,883 ms
コンパイル使用メモリ 258,668 KB
実行使用メモリ 21,144 KB
最終ジャッジ日時 2024-04-22 21:12:28
合計ジャッジ時間 12,258 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
21,008 KB
testcase_01 AC 41 ms
21,140 KB
testcase_02 AC 97 ms
21,012 KB
testcase_03 RE -
testcase_04 AC 346 ms
21,012 KB
testcase_05 AC 37 ms
21,140 KB
testcase_06 AC 46 ms
20,884 KB
testcase_07 AC 39 ms
20,884 KB
testcase_08 AC 31 ms
21,016 KB
testcase_09 AC 331 ms
21,008 KB
testcase_10 AC 68 ms
20,880 KB
testcase_11 AC 37 ms
21,012 KB
testcase_12 AC 35 ms
21,016 KB
testcase_13 AC 363 ms
20,888 KB
testcase_14 AC 61 ms
21,012 KB
testcase_15 AC 46 ms
21,012 KB
testcase_16 AC 60 ms
21,140 KB
testcase_17 AC 28 ms
21,016 KB
testcase_18 RE -
testcase_19 AC 35 ms
21,136 KB
testcase_20 AC 60 ms
20,880 KB
testcase_21 AC 37 ms
20,884 KB
testcase_22 RE -
testcase_23 AC 189 ms
20,888 KB
testcase_24 AC 51 ms
20,888 KB
testcase_25 RE -
testcase_26 AC 29 ms
21,016 KB
testcase_27 RE -
testcase_28 AC 28 ms
21,012 KB
testcase_29 AC 27 ms
21,012 KB
testcase_30 AC 27 ms
21,008 KB
testcase_31 AC 26 ms
20,884 KB
testcase_32 AC 27 ms
21,136 KB
testcase_33 AC 28 ms
21,012 KB
testcase_34 AC 26 ms
21,012 KB
testcase_35 AC 27 ms
21,012 KB
testcase_36 AC 29 ms
21,016 KB
testcase_37 AC 27 ms
20,884 KB
testcase_38 AC 27 ms
20,888 KB
testcase_39 RE -
testcase_40 AC 28 ms
21,144 KB
testcase_41 AC 28 ms
21,012 KB
testcase_42 RE -
testcase_43 AC 29 ms
20,884 KB
testcase_44 AC 28 ms
21,012 KB
testcase_45 AC 27 ms
21,140 KB
testcase_46 AC 27 ms
21,008 KB
testcase_47 AC 27 ms
20,884 KB
testcase_48 RE -
testcase_49 AC 28 ms
20,884 KB
testcase_50 AC 27 ms
20,756 KB
testcase_51 AC 28 ms
21,140 KB
testcase_52 AC 27 ms
21,016 KB
testcase_53 AC 27 ms
21,008 KB
testcase_54 AC 28 ms
20,884 KB
testcase_55 AC 28 ms
20,884 KB
testcase_56 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

// makediv
vector<ll> makediv(ll n){
	vector<ll> ld, ud;
	for (ll i=1; i*i<=n; i++){
		if (n%i == 0){
			ld.push_back(i);
			if (i != n/i){
				ud.push_back(n/i);
			}
		}
	}
	reverse(ud.begin(), ud.end());
	ld.insert(ld.end(), ud.begin(), ud.end());
	return ld;
}
// -----

//defmodfact
const int COMinitMAX = 2222222;
mint fact[COMinitMAX+1], factinv[COMinitMAX+1];

void modfact(){
	fact[0] = 1;
	for (int i=1; i<=COMinitMAX; i++){
		fact[i] = fact[i-1] * i;
	}
	factinv[COMinitMAX] = fact[COMinitMAX].inv();
	for (int i=COMinitMAX-1; i>=0; i--){
		factinv[i] = factinv[i+1] * (i+1);
	}
}

mint cmb(int a, int b){
	if (a<b || b<0) return mint(0);
	return fact[a]*factinv[b]*factinv[a-b];
}
//--------


int main(){
	modfact();
	int n; cin >> n;
	ll m; cin >> m;
	mint ans = 0;
	if (m != 0){
		m = abs(m);
		vector<ll> g = makediv(m);
		for (ll d: g){
			if (abs(d + m / d) % 2 != 0 || abs(d - m / d) % 2 != 0) continue;
			mint bai = 2;
			//if (abs(d + m / d) == abs(d - m / d)) bai = 1;
			ll x = abs(d + m / d) / 2;
			ll y = abs(d - m / d) / 2;
			//cout << d << " " << m / d << '\n';
			if (abs(x) + abs(y) > n) continue;
			for (ll k=0; k<=n; k++){
				if ((k+x)%2 == 1) continue;
				ans += bai * cmb(k, (k+x)/2) * cmb(n-k, (n-k+y)/2) * cmb(n, k);
			}
		}
		//cout << ans.val() << '\n';
		ans *= mint(4).inv().pow(n);
	}else{
		assert(false);
	}
	cout << ans.val() << '\n';
}

0