結果

問題 No.1310 量子アニーリング
ユーザー 👑 jupirojupiro
提出日時 2020-12-07 05:17:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 3,019 bytes
コンパイル時間 2,548 ms
コンパイル使用メモリ 132,744 KB
実行使用メモリ 34,404 KB
最終ジャッジ日時 2023-10-17 15:56:17
合計ジャッジ時間 3,047 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
27,008 KB
testcase_01 AC 32 ms
27,008 KB
testcase_02 AC 33 ms
27,012 KB
testcase_03 AC 35 ms
27,008 KB
testcase_04 AC 33 ms
27,012 KB
testcase_05 AC 32 ms
27,012 KB
testcase_06 AC 32 ms
27,012 KB
testcase_07 AC 32 ms
27,012 KB
testcase_08 AC 31 ms
27,012 KB
testcase_09 AC 31 ms
27,016 KB
testcase_10 AC 31 ms
27,032 KB
testcase_11 AC 35 ms
27,060 KB
testcase_12 AC 36 ms
27,008 KB
testcase_13 AC 37 ms
28,800 KB
testcase_14 AC 38 ms
29,592 KB
testcase_15 AC 37 ms
30,316 KB
testcase_16 AC 36 ms
30,580 KB
testcase_17 AC 39 ms
32,360 KB
testcase_18 AC 40 ms
34,404 KB
testcase_19 AC 37 ms
30,052 KB
testcase_20 AC 33 ms
28,008 KB
testcase_21 AC 33 ms
27,480 KB
testcase_22 AC 40 ms
34,404 KB
testcase_23 AC 36 ms
28,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;
using ull = unsigned long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); }return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long  mod = 998244353;

struct mint {
	long long x;
	mint(long long x = 0) :x((x% mod + mod) % mod) {}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};


constexpr int MAX = 1000000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

mint COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return mint(fac[n] * (finv[k] * finv[n - k] % mod) % mod);
}

mint LCOM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	if (k > n / 2) k = n - k;
	mint res = 1;
	for (int i = 0; i < k; i++) res *= (n - i);
	res *= finv[k];
	return res;
}
int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	COMinit();
	int n; cin >> n;

	vector<mint> tw(n * 5 + 1); tw[0] = 1; for (int i = 1; i <= n * 5; i++) tw[i] = tw[i - 1] * 2;
	mint res = 0;
	for (int cnt = 0; cnt <= n; cnt += 2) {
		ll sum = cnt - (n - cnt);
		sum = abs(sum);
		res += tw[sum] * COM(n, cnt) * 2;
	}
	cout << res.x << "\n";
}
0