結果
問題 | No.1482 Swap Many Permutations |
ユーザー | noshi91 |
提出日時 | 2021-04-16 22:33:29 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,285 bytes |
コンパイル時間 | 2,662 ms |
コンパイル使用メモリ | 137,648 KB |
実行使用メモリ | 10,812 KB |
最終ジャッジ日時 | 2024-07-03 02:41:46 |
合計ジャッジ時間 | 7,774 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 2 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 | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 51 ms
6,760 KB |
testcase_13 | AC | 44 ms
6,696 KB |
testcase_14 | AC | 97 ms
10,332 KB |
testcase_15 | AC | 85 ms
9,428 KB |
testcase_16 | AC | 23 ms
5,376 KB |
testcase_17 | AC | 83 ms
9,380 KB |
testcase_18 | AC | 24 ms
5,376 KB |
testcase_19 | AC | 48 ms
6,440 KB |
testcase_20 | AC | 89 ms
9,664 KB |
testcase_21 | AC | 109 ms
10,120 KB |
testcase_22 | AC | 113 ms
10,552 KB |
testcase_23 | AC | 118 ms
10,688 KB |
testcase_24 | AC | 106 ms
10,556 KB |
testcase_25 | AC | 109 ms
10,560 KB |
testcase_26 | AC | 114 ms
10,680 KB |
testcase_27 | AC | 146 ms
10,688 KB |
testcase_28 | AC | 105 ms
10,680 KB |
testcase_29 | AC | 101 ms
10,680 KB |
testcase_30 | AC | 126 ms
10,556 KB |
testcase_31 | AC | 100 ms
10,556 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | AC | 4 ms
5,376 KB |
testcase_38 | AC | 15 ms
5,376 KB |
testcase_39 | AC | 7 ms
5,376 KB |
testcase_40 | AC | 5 ms
5,376 KB |
testcase_41 | AC | 28 ms
5,376 KB |
testcase_42 | AC | 11 ms
5,376 KB |
testcase_43 | AC | 11 ms
5,376 KB |
testcase_44 | AC | 11 ms
5,376 KB |
testcase_45 | AC | 13 ms
5,376 KB |
testcase_46 | AC | 14 ms
5,376 KB |
ソースコード
// i = 2 が解けません Ω\ζ°)チーン //#define NDEBUG #include <algorithm> #include <cassert> #include <cstddef> #include <cstdint> #include <iostream> #include <utility> #include <vector> namespace n91 { using i32 = std::int32_t; using i64 = std::int64_t; using u32 = std::uint32_t; using u64 = std::uint64_t; using isize = std::ptrdiff_t; using usize = std::size_t; struct rep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { ++i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr rep(const usize f, const usize l) noexcept : f(std::min(f, l)), l(l) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; struct revrep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { --i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr revrep(const usize f, const usize l) noexcept : f(l - 1), l(std::min(f, l) - 1) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; template <class T> auto md_vec(const usize n, const T &value) { return std::vector<T>(n, value); } template <class... Args> auto md_vec(const usize n, Args... args) { return std::vector<decltype(md_vec(args...))>(n, md_vec(args...)); } template <class T> constexpr T difference(const T &a, const T &b) noexcept { return a < b ? b - a : a - b; } template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; } template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; } template <class F> class rec_lambda { F f; public: rec_lambda(F &&f) : f(std::move(f)) {} template <class... Args> auto operator()(Args &&... args) const { return f(*this, std::forward<Args>(args)...); } }; template <class F> auto make_rec(F &&f) { return rec_lambda<F>(std::move(f)); } template <class T> T scan() { T ret; std::cin >> ret; return ret; } constexpr char eoln = '\n'; template <class T> T ceildiv(const T &l, const T &r) { return l / r + (l % r != 0 ? 1 : 0); } } // namespace n91 #include <vector> namespace n91 { template <class T> class mint_utils { using usize = std::size_t; std::vector<T> fact_, inv_fact_; public: mint_utils() : fact_(), inv_fact_() {} explicit mint_utils(const usize n) : fact_(n + 1), inv_fact_(n + 1) { fact_[0] = 1; for (usize i = 0; i != n; i += 1) { fact_[i + 1] = fact_[i] * (i + 1); } inv_fact_[n] = T(1) / fact_[n]; for (usize i = n; i != 0; i -= 1) { inv_fact_[i - 1] = inv_fact_[i] * i; } } T fact(const usize n) const { return fact_[n]; } T inv_fact(const usize n) const { return inv_fact_[n]; } T binom(const usize n, const usize r) const { return fact_[n] * inv_fact_[r] * inv_fact_[n - r]; } T homo(const usize n, const usize r) const { return fact_[n + r - 1] * inv_fact_[n] * inv_fact_[r - 1]; } }; } // namespace n91 #include <atcoder/convolution> #include <atcoder/internal_math> #include <atcoder/modint> #include <map> #include <numeric> namespace n91 { void main_() { using mint = atcoder::static_modint<998244353>; //* std::ios::sync_with_stdio(false); std::cin.tie(nullptr); //*/ const usize n = scan<usize>(); const usize m = scan<usize>(); std::vector<usize> b(n), c(n); for (const usize i : rep(0, n)) { std::cin >> b[i] >> c[i]; } if (m == 2) { for (const usize i : rep(0, n)) { if (i == 0) { std::cout << 1 << eoln; } else if (i == 1) { if (b[0] == b[1]) { std::cout << 0 << eoln; } else { std::cout << 2 << eoln; } } else { std::cout << 0 << eoln; } } return; } const auto parity = [m](const usize b) -> bool { bool ret = false; std::vector<bool> used(m, false); for (const usize i : rep(0, m)) { if (used[i]) { continue; } usize count = 0; usize v = i; do { used[v] = true; count += 1; v = (b * v) % m; } while (v != i); if (count % 2 == 0) { ret = !ret; } } return ret; }; std::vector<bool> parities(m); { const usize pr = atcoder::internal::primitive_root_constexpr(m); std::vector<usize> log(m); { usize v = 1; for (const usize i : rep(0, m - 1)) { log[v] = i; v = v * pr % m; } } std::map<usize, bool> memo; // gcd, parity for (const usize i : rep(1, m)) { const usize g = std::gcd(m - 1, log[i]); if (!memo.count(g)) { memo[g] = parity(i); } parities[i] = memo[g]; } } u64 one = 0, zero = 0; for (const usize i : rep(1, m)) { if (parities[i]) { one += 1; } else { zero += 1; } } one *= m; zero *= m; const mint_utils<mint> util(n + 1); std::vector<mint> odd, even; { mint one_fact = 1, zero_fact = 1; std::vector<mint> one_odd(n + 1), one_even(n + 1), zero_a(n + 1); for (const usize i : rep(0, n + 1)) { if (i % 2 == 0) { one_even[i] = one_fact / util.fact(i); } else { one_odd[i] = one_fact / util.fact(i); } zero_a[i] = zero_fact / util.fact(i); one_fact *= mint(one) - i; zero_fact *= mint(zero) - i; } odd = atcoder::convolution(one_odd, zero_a); even = atcoder::convolution(one_even, zero_a); } bool current_p = false; for (const usize i : rep(0, n)) { if (parities[c[i]]) { current_p = !current_p; } if (i == 0) { std::cout << 1 << eoln; continue; } if (i == 1) { std::cout << (mint(m) * mint(m - 1)).val() << eoln; continue; } if (current_p) { std::cout << (odd[i + 1] * util.fact(i + 1)).val() << eoln; } else { std::cout << (even[i + 1] * util.fact(i + 1)).val() << eoln; } } } } // namespace n91 int main() { n91::main_(); return 0; }