結果
問題 | No.1482 Swap Many Permutations |
ユーザー | SSRS |
提出日時 | 2021-04-16 22:11:25 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 743 ms / 2,000 ms |
コード長 | 3,688 bytes |
コンパイル時間 | 1,766 ms |
コンパイル使用メモリ | 180,332 KB |
実行使用メモリ | 20,560 KB |
最終ジャッジ日時 | 2024-07-03 02:02:35 |
合計ジャッジ時間 | 14,389 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 176 ms
11,576 KB |
testcase_13 | AC | 131 ms
11,516 KB |
testcase_14 | AC | 312 ms
20,076 KB |
testcase_15 | AC | 272 ms
19,212 KB |
testcase_16 | AC | 73 ms
7,352 KB |
testcase_17 | AC | 263 ms
19,008 KB |
testcase_18 | AC | 76 ms
7,600 KB |
testcase_19 | AC | 152 ms
11,300 KB |
testcase_20 | AC | 283 ms
19,320 KB |
testcase_21 | AC | 453 ms
19,776 KB |
testcase_22 | AC | 456 ms
20,432 KB |
testcase_23 | AC | 491 ms
20,436 KB |
testcase_24 | AC | 373 ms
20,440 KB |
testcase_25 | AC | 400 ms
20,440 KB |
testcase_26 | AC | 464 ms
20,432 KB |
testcase_27 | AC | 743 ms
20,560 KB |
testcase_28 | AC | 376 ms
20,428 KB |
testcase_29 | AC | 339 ms
20,436 KB |
testcase_30 | AC | 552 ms
20,432 KB |
testcase_31 | AC | 328 ms
20,432 KB |
testcase_32 | AC | 436 ms
20,432 KB |
testcase_33 | AC | 718 ms
20,432 KB |
testcase_34 | AC | 393 ms
20,440 KB |
testcase_35 | AC | 322 ms
20,436 KB |
testcase_36 | AC | 404 ms
20,432 KB |
testcase_37 | AC | 13 ms
5,376 KB |
testcase_38 | AC | 88 ms
5,376 KB |
testcase_39 | AC | 29 ms
5,376 KB |
testcase_40 | AC | 21 ms
5,376 KB |
testcase_41 | AC | 183 ms
5,376 KB |
testcase_42 | AC | 76 ms
5,376 KB |
testcase_43 | AC | 80 ms
5,376 KB |
testcase_44 | AC | 78 ms
5,376 KB |
testcase_45 | AC | 93 ms
5,376 KB |
testcase_46 | AC | 105 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; long long modpow(long long a, long long b, long long mod = MOD){ long long ans = 1; while (b > 0){ if (b % 2 == 1){ ans *= a; ans %= mod; } a *= a; a %= mod; b /= 2; } return ans; } long long modinv(long long a){ return modpow(a, MOD - 2); } vector<long long> mf = {1}; vector<long long> mfi = {1}; long long modfact(int n){ if (mf.size() > n){ return mf[n]; } else { for (int i = mf.size(); i <= n; i++){ long long next = mf.back() * i % MOD; mf.push_back(next); mfi.push_back(modinv(next)); } return mf[n]; } } long long modfactinv(int n){ if (mfi.size() > n){ return mfi[n]; } else { return modinv(modfact(n)); } } vector<long long> ntt(vector<long long> A, bool inv){ int N = A.size(); long long r = 3; if (inv){ r = modinv(r); } vector<long long> B(N); for (int i = N / 2; i > 0; i /= 2){ long long z = modpow(r, (MOD - 1) / (N / i)); long long z2 = 1; for (int j = 0; j < N; j += i * 2){ for (int k = 0; k < i; k++){ A[i + j + k] *= z2; A[i + j + k] %= MOD; B[j / 2 + k] = (A[j + k] + A[i + j + k]) % MOD; B[N / 2 + j / 2 + k] = (A[j + k] - A[i + j + k] + MOD) % MOD; } z2 = z2 * z % MOD; } swap(A, B); } if (inv){ int Ninv = modinv(N); for (int i = 0; i < N; i++){ A[i] = A[i] * Ninv % MOD; } } return A; } vector<long long> convolution(vector<long long> A, vector<long long> B, int d = -1){ int deg = A.size() + B.size() - 1; int N = 1; while (N < deg){ N *= 2; } A.resize(N); B.resize(N); A = ntt(A, false); B = ntt(B, false); vector<long long> ans(N); for (int i = 0; i < N; i++){ ans[i] = A[i] * B[i] % MOD; } ans = ntt(ans, true); if (d != -1){ deg = d; } ans.resize(deg); return ans; } int main(){ int N; long long M; cin >> N >> M; vector<int> B(N), C(N); for (int i = 0; i < N; i++){ cin >> B[i] >> C[i]; } cout << 1 << endl; if (B[0] == B[1] && C[0] == C[1]){ cout << 0 << endl; } else { cout << (M * (M - 1)) % MOD << endl; } if (M == 2){ for (int i = 2; i < N; i++){ cout << 0 << endl; } } else { vector<int> f; for (int i = M - 1; i >= 1; i--){ if ((M - 1) % i == 0){ f.push_back(i); } } vector<int> mn(M); for (int i = 1; i < M; i++){ for (int j : f){ if (modpow(i, j, M) == 1){ mn[i] = j; } } } vector<long long> cnt(2, 0); for (int i = 1; i < M; i++){ int x = (M - 1) / mn[i] * (mn[i] - 1); cnt[x % 2] += M; } vector<long long> f1(N + 1); vector<long long> g(N + 1); f1[0] = 1; g[0] = 1; for (int i = 0; i < N; i++){ if (i >= cnt[1]){ f1[i + 1] = 0; } else { f1[i + 1] = f1[i] * ((cnt[1] - i) % MOD) % MOD; } if (i >= cnt[0]){ g[i + 1] = 0; } else { g[i + 1] = g[i] * ((cnt[0] - i) % MOD) % MOD; } } for (int i = 0; i <= N; i++){ f1[i] *= modfactinv(i); f1[i] %= MOD; g[i] *= modfactinv(i); g[i] %= MOD; } vector<long long> f2 = f1; for (int i = 1; i <= N; i += 2){ f1[i] = 0; } for (int i = 0; i <= N; i += 2){ f2[i] = 0; } vector<long long> h1 = convolution(f1, g); vector<long long> h2 = convolution(f2, g); int sum = 0; for (int i = 0; i < N; i++){ sum += (M - 1) / mn[C[i]] * (mn[C[i]] - 1) % 2; if (i >= 2){ if (i % 2 == 0 || sum % 2 == 0){ cout << h1[i + 1] * modfact(i + 1) % MOD << endl; } else { cout << h2[i + 1] * modfact(i + 1) % MOD << endl; } } } } }