結果
問題 | No.1310 量子アニーリング |
ユーザー | t33f |
提出日時 | 2020-12-07 00:37:45 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 1,646 bytes |
コンパイル時間 | 740 ms |
コンパイル使用メモリ | 82,684 KB |
実行使用メモリ | 6,416 KB |
最終ジャッジ日時 | 2023-10-17 15:46:59 |
合計ジャッジ時間 | 1,720 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 2 ms
4,348 KB |
testcase_04 | AC | 2 ms
4,348 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 2 ms
4,348 KB |
testcase_07 | AC | 2 ms
4,348 KB |
testcase_08 | AC | 2 ms
4,348 KB |
testcase_09 | AC | 2 ms
4,348 KB |
testcase_10 | AC | 2 ms
4,348 KB |
testcase_11 | AC | 2 ms
4,348 KB |
testcase_12 | AC | 2 ms
4,348 KB |
testcase_13 | AC | 7 ms
4,348 KB |
testcase_14 | AC | 10 ms
4,568 KB |
testcase_15 | AC | 12 ms
4,832 KB |
testcase_16 | AC | 12 ms
4,832 KB |
testcase_17 | AC | 17 ms
5,624 KB |
testcase_18 | AC | 22 ms
6,416 KB |
testcase_19 | AC | 11 ms
4,568 KB |
testcase_20 | AC | 6 ms
4,348 KB |
testcase_21 | AC | 4 ms
4,348 KB |
testcase_22 | AC | 22 ms
6,416 KB |
testcase_23 | AC | 7 ms
4,348 KB |
ソースコード
#include <cmath> #include <iostream> using namespace std; class ModComb { long long *fact, *facti; const int mod; public: explicit ModComb(int n, int m) : mod(m) { fact = new long long[n+1]; facti = new long long[n+1]; fact[0] = 1; facti[0] = 1; for (int i = 1; i <= n; i++) fact[i] = (fact[i-1] * i) % m; // calc 1/n! long long &inv = facti[n], pw = fact[n]; inv = 1; for (int e = mod-2; e > 0; e /= 2) { if (e&1) inv = inv * pw % mod; pw = pw * pw % mod; } for (int i = n-1; i > 0; i--) facti[i] = (facti[i+1] * (i+1)) % m; } ~ModComb() { if (fact) delete[] fact; if (facti) delete[] facti; } long long getFact(int n) const { return fact[n]; } long long getFactInv(int n) const { return facti[n]; } long long getComb(int n, int k) const { if (n < 0 || k < 0 || k > n) return 0; return fact[n] * facti[k] % mod * facti[n-k] % mod; } long long getPerm(int n, int k) const { if (n < 0 || k < 0 || k > n) return 0; return fact[n] * facti[n-k] % mod; } }; long long modexp(int x, long long e, int m) { long long ans = 1, p = x % m; while (e > 0) { if (e % 2 != 0) ans = (ans * p) % m; p = (p * p) % m; e >>= 1; } return ans; } int main() { int n; cin >> n; long long ans = 0; constexpr int M = 998244353; ModComb mc(n, M); for (int k = 0; k <= n; k += 2) ans += 2 * mc.getComb(n, k) % M * modexp(2, abs(n-2*k), M) % M; cout << ans % M << endl; }