結果
問題 | No.2747 Permutation Adjacent Sum |
ユーザー | shobonvip |
提出日時 | 2024-04-21 04:30:59 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,017 ms / 3,000 ms |
コード長 | 2,913 bytes |
コンパイル時間 | 4,657 ms |
コンパイル使用メモリ | 273,600 KB |
実行使用メモリ | 58,104 KB |
最終ジャッジ日時 | 2024-10-13 02:57:22 |
合計ジャッジ時間 | 45,261 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 899 ms
36,872 KB |
testcase_01 | AC | 977 ms
21,888 KB |
testcase_02 | AC | 965 ms
29,868 KB |
testcase_03 | AC | 1,132 ms
21,784 KB |
testcase_04 | AC | 1,235 ms
37,272 KB |
testcase_05 | AC | 2,017 ms
58,048 KB |
testcase_06 | AC | 484 ms
39,184 KB |
testcase_07 | AC | 1,564 ms
36,484 KB |
testcase_08 | AC | 800 ms
50,712 KB |
testcase_09 | AC | 1,041 ms
56,368 KB |
testcase_10 | AC | 776 ms
24,776 KB |
testcase_11 | AC | 1,450 ms
36,516 KB |
testcase_12 | AC | 1,100 ms
20,884 KB |
testcase_13 | AC | 667 ms
28,224 KB |
testcase_14 | AC | 843 ms
49,852 KB |
testcase_15 | AC | 778 ms
56,256 KB |
testcase_16 | AC | 517 ms
37,080 KB |
testcase_17 | AC | 1,542 ms
55,348 KB |
testcase_18 | AC | 1,186 ms
54,916 KB |
testcase_19 | AC | 900 ms
23,184 KB |
testcase_20 | AC | 870 ms
37,368 KB |
testcase_21 | AC | 1,147 ms
50,784 KB |
testcase_22 | AC | 1,370 ms
51,692 KB |
testcase_23 | AC | 1,586 ms
35,676 KB |
testcase_24 | AC | 240 ms
36,164 KB |
testcase_25 | AC | 1,056 ms
29,700 KB |
testcase_26 | AC | 745 ms
49,916 KB |
testcase_27 | AC | 1,183 ms
51,080 KB |
testcase_28 | AC | 972 ms
50,524 KB |
testcase_29 | AC | 507 ms
38,784 KB |
testcase_30 | AC | 1,670 ms
57,976 KB |
testcase_31 | AC | 1,663 ms
57,976 KB |
testcase_32 | AC | 1,656 ms
57,976 KB |
testcase_33 | AC | 1,646 ms
58,104 KB |
testcase_34 | AC | 1,659 ms
57,992 KB |
testcase_35 | AC | 25 ms
21,012 KB |
testcase_36 | AC | 26 ms
20,884 KB |
testcase_37 | AC | 25 ms
20,884 KB |
testcase_38 | AC | 27 ms
20,884 KB |
testcase_39 | AC | 25 ms
20,888 KB |
testcase_40 | AC | 24 ms
20,880 KB |
testcase_41 | AC | 24 ms
21,012 KB |
ソースコード
#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; } //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]; } //-------- vector<mint> poly_inv(vector<mint> &a, int M = -314159265){ if (M == -314159265) M = (int)a.size(); else if (M <= 0) return {}; int n = a.size(); mint r = a[0].pow((ll)(mint::mod())-2); int m = 1; vector<mint> res = {r}; while (m < M){ vector<mint> f = a; f.resize(2 * m); vector<mint> g = res; g.resize(2 * m); internal::butterfly(f); internal::butterfly(g); for (int i=0; i<2*m; i++){ f[i] = f[i] * g[i]; } internal::butterfly_inv(f); for (int i=0; i<m; i++){ f[i] = f[i + m]; } for (int i=0; i<m; i++){ f[i + m] = 0; } internal::butterfly(f); for (int i=0; i<2*m; i++){ f[i] = f[i] * g[i]; } internal::butterfly_inv(f); mint iz = mint(2*m).inv(); iz = -iz * iz; for (int i=0; i<m; i++){ f[i] = f[i] * iz; } res.insert(res.end(), f.begin(), f.begin()+m); m <<= 1; } res.resize(M); return res; } int main(){ modfact(); ll n, k; cin >> n >> k; vector<mint> f(k+2); vector<mint> g(k+2); mint val = 1; rep(i,0,k+2){ val *= n + 1; f[i] = factinv[i + 1] * val; g[i] = factinv[i + 1]; } vector<mint> h = convolution(f, poly_inv(g)); h.resize(k+2); mint ans = n * h[k] * fact[k] - h[k+1] * fact[k+1]; ans *= 2; if (n >= 700'000'000){ ans *= 293833759; rep(i,700'000'000,n){ ans *= i; } }else if (n >= 400'000'000){ ans *= 55395755; rep(i,400'000'000,n){ ans *= i; } }else{ rep(i,2,n){ ans *= i; } } cout << ans.val() << '\n'; }