結果

問題 No.2514 Twelvefold Way Returns
ユーザー risujiroh
提出日時 2023-10-20 22:23:39
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 24 ms / 3,000 ms
コード長 5,678 bytes
コンパイル時間 3,732 ms
コンパイル使用メモリ 259,176 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-20 19:53:39
合計ジャッジ時間 5,269 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#if __INCLUDE_LEVEL__ == 0
#include __BASE_FILE__
using Fp = atcoder::modint998244353;
using T = pair<Fp, Fp>;
namespace atcoder {
T operator+(const T& x, const T& y) {
return {x.first + y.first, x.second + y.second};
}
T operator*(const T& x, const T& y) {
return {x.first * y.first + x.second * y.second * 3,
x.first * y.second + x.second * y.first};
}
T& operator*=(T& x, const T& y) { return x = x * y; }
} // namespace atcoder
namespace {
Comb<Fp> comb(1000);
void solve() {
int n, m;
scan(n, m);
T omega{-1 / Fp(2), Fp(atcoder::internal::primitive_root<Fp::mod()>)
.pow((Fp::mod() - 1) / 4) /
2};
Fp ans = 0;
for (int i : rep(m + 1)) {
for (int j : rep(m - i + 1)) {
int k = m - i - j;
T t = power(T{i, 0} + T{j, 0} * omega + T{k, 0} * omega * omega, n);
if (int r = (j * 2 + k) % 3) {
t *= power(omega, r);
}
ans += comb.binom(m, i) * comb.binom(m - i, j) * t.first;
}
}
ans /= Fp(3).pow(m);
print(ans);
}
} // namespace
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}
#else // __INCLUDE_LEVEL__
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/modint>
template <class T>
vector<T> make_vector_for_overwrite(int n) {
static_assert(is_trivially_destructible_v<T>);
vector<T> v;
v.reserve(n);
auto p = (T**)&v;
p[1] = p[2];
return v;
}
template <class T>
class Comb {
public:
Comb() = default;
explicit Comb(int max_n)
: fact_(make_vector_for_overwrite<T>(max_n + 1)),
recip_fact_(make_vector_for_overwrite<T>(max_n + 1)) {
fact_[0] = 1;
for (int n = 1; n <= max_n; ++n) {
fact_[n] = fact_[n - 1] * n;
}
recip_fact_[max_n] = 1 / fact_[max_n];
for (int n = max_n; 1 <= n; --n) {
recip_fact_[n - 1] = n * recip_fact_[n];
}
}
T recip(int n) const {
assert(n);
return n < 0 ? -recip(-n) : recip_fact_[n] * fact_[n - 1];
}
T fact(int n) const {
assert(0 <= n);
return fact_[n];
}
T recip_fact(int n) const { return n < 0 ? 0 : recip_fact_[n]; }
T falling_fact(int n, int k) const {
assert(0 <= n || n < k);
if (n < 0) {
T t = falling_fact(k - n - 1, k);
return k & 1 ? -t : t;
}
return n < k ? 0 : recip_fact(n - k) * fact(n);
}
T recip_falling_fact(int n, int k) const {
assert(n < 0 || k <= n);
return falling_fact(n - k, -k);
}
T rising_fact(int n, int k) const {
assert(n <= 0 || 0 < n + k);
return falling_fact(n + k - 1, k);
}
T recip_rising_fact(int n, int k) const {
assert(0 < n || n + k <= 0);
return falling_fact(n - 1, -k);
}
T binom(int n, int k) const {
if ((n < 0) ^ (k < 0) ^ (n < k)) {
return 0;
}
if (n < 0 && k < 0) {
k = n - k;
}
return recip_fact(k) * falling_fact(n, k);
}
T recip_binom(int n, int k) const {
assert((0 <= n) ^ (0 <= k) ^ (k <= n));
k = max(k, n - k);
return recip_falling_fact(n, k) * fact(k);
}
T multiset(int n, int k) const { return binom(n + k - 1, k); }
T recip_multiset(int n, int k) const {
assert((0 < n) ^ (0 <= k) ^ (0 < n + k));
return recip_binom(n + k - 1, k);
}
private:
vector<T> fact_;
vector<T> recip_fact_;
};
template <class T, class N>
constexpr T power(T x, N n) {
assert(0 < n);
while (n % 2 == 0) {
x *= x;
n >>= 1;
}
T ret = x;
while (n >>= 1) {
x *= x;
if (n % 2) {
ret *= x;
}
}
return ret;
}
namespace std {
template <class T1, class T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
return is >> p.first >> p.second;
}
template <class... Ts>
istream& operator>>(istream& is, tuple<Ts...>& t) {
return apply([&is](auto&... xs) -> istream& { return (is >> ... >> xs); }, t);
}
template <class R, enable_if_t<!is_convertible_v<R, string>>* = nullptr>
auto operator>>(istream& is, R&& r) -> decltype(is >> *begin(r)) {
for (auto&& e : r) {
is >> e;
}
return is;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
return os << p.first << ' ' << p.second;
}
template <class... Ts>
ostream& operator<<(ostream& os, const tuple<Ts...>& t) {
auto f = [&os](const auto&... xs) -> ostream& {
[[maybe_unused]] auto sep = "";
((os << exchange(sep, " ") << xs), ...);
return os;
};
return apply(f, t);
}
template <class R, enable_if_t<!is_convertible_v<R, string_view>>* = nullptr>
auto operator<<(ostream& os, R&& r) -> decltype(os << *begin(r)) {
auto sep = "";
for (auto&& e : r) {
os << exchange(sep, " ") << e;
}
return os;
}
} // namespace std
namespace atcoder {
template <class T, internal::is_modint_t<T>* = nullptr>
istream& operator>>(istream& is, T& x) {
int v;
is >> v;
x = T::raw(v);
return is;
}
template <class T, internal::is_modint_t<T>* = nullptr>
ostream& operator<<(ostream& os, const T& x) {
return os << x.val();
}
} // namespace atcoder
template <class... Ts>
void scan(Ts&&... xs) {
(cin >> ... >> xs);
}
template <class... Ts>
void print(Ts&&... xs) {
cout << tie(xs...) << '\n';
}
inline auto rep(int l, int r) { return views::iota(min(l, r), r); }
inline auto rep(int n) { return rep(0, n); }
inline auto rep1(int l, int r) { return rep(l, r + 1); }
inline auto rep1(int n) { return rep(1, n + 1); }
inline auto per(int l, int r) { return rep(l, r) | views::reverse; }
inline auto per(int n) { return per(0, n); }
inline auto per1(int l, int r) { return per(l, r + 1); }
inline auto per1(int n) { return per(1, n + 1); }
inline auto len = ranges::ssize;
#endif // __INCLUDE_LEVEL__
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0