結果

問題 No.1310 量子アニーリング
ユーザー
提出日時 2020-12-07 19:12:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,193 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 94,528 KB
実行使用メモリ 8,260 KB
最終ジャッジ日時 2024-09-17 14:00:58
合計ジャッジ時間 2,178 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long fac[200020], finv[200020], inv[200020];
long long mod = 998244353;
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < 200020; 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;
	}
}
long long COM(long long n, long long k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main() {
	COMinit();
	long long n;
	cin >> n;
	long long now = n;
	long long ans = 0;
	for (long long i = 0; i <= n; i += 2) {
		long long x = 2;
		long long y = abs(now);
		long long ans1 = 1;
		while (y > 0) {
			if ((y & 1) == 1) {
				ans1 = ans1 * x % mod;
			}
			x = x * x % mod;
			y >>= 1;
		}
		ans1 *= COM(n, i);
		ans1 %= mod;
		ans1 *= 2;
		ans %= mod;
		ans += ans1;
		ans %= mod;
		now -= 4;
	}
	cout << ans << endl;
}
0