結果
問題 | No.1138 No Bingo! |
ユーザー | leafirby |
提出日時 | 2020-07-26 23:39:33 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 883 ms / 3,000 ms |
コード長 | 4,273 bytes |
コンパイル時間 | 2,180 ms |
コンパイル使用メモリ | 213,488 KB |
実行使用メモリ | 22,376 KB |
最終ジャッジ日時 | 2024-06-28 19:41:41 |
合計ジャッジ時間 | 12,716 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 259 ms
11,928 KB |
testcase_04 | AC | 521 ms
20,484 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 364 ms
12,396 KB |
testcase_10 | AC | 510 ms
19,864 KB |
testcase_11 | AC | 883 ms
20,440 KB |
testcase_12 | AC | 155 ms
8,000 KB |
testcase_13 | AC | 44 ms
5,376 KB |
testcase_14 | AC | 729 ms
20,260 KB |
testcase_15 | AC | 323 ms
12,668 KB |
testcase_16 | AC | 672 ms
20,440 KB |
testcase_17 | AC | 722 ms
19,768 KB |
testcase_18 | AC | 718 ms
19,716 KB |
testcase_19 | AC | 339 ms
12,848 KB |
testcase_20 | AC | 847 ms
20,028 KB |
testcase_21 | AC | 635 ms
22,376 KB |
testcase_22 | AC | 603 ms
21,980 KB |
testcase_23 | AC | 14 ms
5,376 KB |
testcase_24 | AC | 304 ms
12,416 KB |
testcase_25 | AC | 353 ms
11,736 KB |
testcase_26 | AC | 176 ms
7,824 KB |
testcase_27 | AC | 254 ms
11,896 KB |
testcase_28 | AC | 150 ms
7,804 KB |
testcase_29 | AC | 137 ms
7,816 KB |
ソースコード
#include <bits/stdc++.h> /*#include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/multiprecision/cpp_int.hpp> */#pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; /*namespace mp = boost::multiprecision; using Bint = mp::cpp_int; using Real = mp::number<mp::cpp_dec_float<1024>>; */#define lli long long int #define uli unsigned long long int #define INF 999999999999 #define rep(i,m,n) for(lli i = m;i < n;i++) #define rrep(i,m,n) for(lli i=m-1;i>=n;i--) #define pb(n) push_back(n) #define UE(N) N.erase(unique(N.begin(),N.end()),N.end()); #define Sort(n) sort(n.begin(), n.end()) #define Rev(n) reverse(n.begin(),n.end()) #define Out(S) cout << S << endl #define NeOut(S) cout << S #define HpOut(S) cout << setprecision(50) << S << endl #define Vec(K,L,N,S) vector<L> K(N,S) #define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S)) #define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S))) #define pint pair<lli,lli> #define paf(L,R) pair<L,R> #define mod 998244353 #define MAX 10000000 #define ALL(a) a.begin(),a.end() #define chmax(a, b) a = (((a)<(b)) ? (b) : (a)) #define chmin(a, b) a = (((a)>(b)) ? (b) : (a)) long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a/b; a -= t*b; swap(a, b); u -= t*v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } long long modpow(long long n, long long k, long long m) { if (!k) return 1; else if(k & 1)return modpow(n,k-1,m)*n%m; else{ long long temp=modpow(n,k/2,m); return temp*temp%m; } } const long long PR = 3; // to be set appropriately void trans(vector<long long> &v, bool inv = false) { int n = (int)v.size(); for (int i = 0, j = 1; j < n-1; j++) { for (int k = n>>1; k > (i ^= k); k >>= 1); if (i > j) swap(v[i], v[j]); } for (int t = 2; t <= n; t <<= 1) { long long bw = modpow(PR, (mod-1)/t, mod); if (inv) bw = modinv(bw, mod); for (int i = 0; i < n; i += t) { long long w = 1; for (int j = 0; j < t/2; ++j) { int j1 = i + j, j2 = i + j + t/2; long long c1 = v[j1], c2 = v[j2] * w % mod; v[j1] = c1 + c2; v[j2] = c1 - c2 + mod; while (v[j1] >= mod) v[j1] -= mod; while (v[j2] >= mod) v[j2] -= mod; w = w * bw % mod; } } } if (inv) { long long inv_n = modinv(n, mod); for (int i = 0; i < n; ++i) v[i] = v[i] * inv_n % mod; } } vector<long long> NTT(vector<long long> A, vector<long long> B) { int size_a = 1; while (size_a < A.size()) size_a <<= 1; int size_b = 1; while (size_b < B.size()) size_b <<= 1; int size_fft = max(size_a, size_b) << 1; vector<long long> cA(size_fft, 0), cB(size_fft, 0), cC(size_fft, 0); for (int i = 0; i < A.size(); ++i) cA[i] = A[i]; for (int i = 0; i < B.size(); ++i) cB[i] = B[i]; trans(cA); trans(cB); for (int i = 0; i < size_fft; ++i) cC[i] = cA[i] * cB[i] % mod; trans(cC, true); vector<long long> res((int)A.size() + (int)B.size() - 1); for (int i = 0; i < res.size(); ++i) res[i] = cC[i]; return res; } vector<long long> mod_pow_poly(long long N, vector<long long> &res){ if (!N) return {1}; else if(N & 1)return NTT(mod_pow_poly(N-1, res), res); else{ vector<long long> temp=mod_pow_poly(N/2, res); return NTT(temp, temp); } } vector<long long> solve(long long N){ vector<long long> res = {2, 4, 1}, temp = {1}; if(N & 1) temp = {1, 1}; N /= 2; return NTT(mod_pow_poly(N, res), temp); } int main(){ ios::sync_with_stdio(false); cin.tie(0); long long N, M,sum=0; cin >> N; assert(1 <= N && N <= 200000); vector<long long> fact(N+1,1); rep(i,2,N+1)fact[i]=fact[i-1]*i%mod; rep(i,2,N+1)sum=(sum+mod+(long long)pow(-1,i%2)*(fact[N]*modinv(fact[i],mod)%mod))%mod; sum = (sum << 1) % mod; auto dp = solve(N); rep(i,0,N+1) { if((N - i) & 1) sum = (sum + dp[i] * fact[i] % mod) % mod; else sum = (sum + mod - dp[i] * fact[i] % mod) % mod; } Out((fact[N] - sum + mod) % mod); }