結果
問題 | No.2747 Permutation Adjacent Sum |
ユーザー | shobonvip |
提出日時 | 2024-04-21 04:28:59 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,608 ms / 3,000 ms |
コード長 | 2,822 bytes |
コンパイル時間 | 4,600 ms |
コンパイル使用メモリ | 274,584 KB |
実行使用メモリ | 58,100 KB |
最終ジャッジ日時 | 2024-10-13 02:55:17 |
合計ジャッジ時間 | 60,302 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 497 ms
36,648 KB |
testcase_01 | AC | 592 ms
21,756 KB |
testcase_02 | AC | 1,856 ms
29,864 KB |
testcase_03 | AC | 2,040 ms
21,780 KB |
testcase_04 | AC | 2,163 ms
37,276 KB |
testcase_05 | AC | 2,118 ms
57,908 KB |
testcase_06 | AC | 509 ms
39,312 KB |
testcase_07 | AC | 1,606 ms
36,488 KB |
testcase_08 | AC | 841 ms
50,712 KB |
testcase_09 | AC | 636 ms
56,372 KB |
testcase_10 | AC | 813 ms
24,776 KB |
testcase_11 | AC | 1,481 ms
36,564 KB |
testcase_12 | AC | 699 ms
20,864 KB |
testcase_13 | AC | 1,543 ms
28,252 KB |
testcase_14 | AC | 1,738 ms
49,744 KB |
testcase_15 | AC | 821 ms
56,224 KB |
testcase_16 | AC | 499 ms
36,912 KB |
testcase_17 | AC | 1,594 ms
55,344 KB |
testcase_18 | AC | 811 ms
55,036 KB |
testcase_19 | AC | 1,759 ms
23,052 KB |
testcase_20 | AC | 1,739 ms
37,164 KB |
testcase_21 | AC | 1,176 ms
50,664 KB |
testcase_22 | AC | 2,304 ms
51,636 KB |
testcase_23 | AC | 1,637 ms
35,608 KB |
testcase_24 | AC | 1,947 ms
36,028 KB |
testcase_25 | AC | 1,088 ms
29,576 KB |
testcase_26 | AC | 2,472 ms
49,908 KB |
testcase_27 | AC | 1,240 ms
51,184 KB |
testcase_28 | AC | 1,009 ms
50,524 KB |
testcase_29 | AC | 1,359 ms
38,776 KB |
testcase_30 | AC | 2,563 ms
57,964 KB |
testcase_31 | AC | 2,569 ms
58,100 KB |
testcase_32 | AC | 2,589 ms
58,096 KB |
testcase_33 | AC | 2,585 ms
57,968 KB |
testcase_34 | AC | 2,608 ms
57,964 KB |
testcase_35 | AC | 28 ms
20,880 KB |
testcase_36 | AC | 28 ms
20,864 KB |
testcase_37 | AC | 29 ms
20,864 KB |
testcase_38 | AC | 27 ms
20,884 KB |
testcase_39 | AC | 28 ms
20,884 KB |
testcase_40 | AC | 28 ms
20,884 KB |
testcase_41 | AC | 28 ms
20,864 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 >= 500'000'000){ ans *= 15814281; rep(i,500'000'000,n){ ans *= i; } }else{ rep(i,2,n){ ans *= i; } } cout << ans.val() << '\n'; }