結果
問題 | No.2793 Mancala Master |
ユーザー |
|
提出日時 | 2024-06-22 01:44:33 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,598 bytes |
コンパイル時間 | 2,716 ms |
コンパイル使用メモリ | 244,024 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 10:45:20 |
合計ジャッジ時間 | 4,669 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 16 WA * 1 |
ソースコード
// Problem: No.2793 Mancala Master// Group: yukicoder// URL: https://yukicoder.me/problems/no/2793// Memory Limit: 512 MB// Time Limit: 2000 ms// Author: lingfunny//// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>using namespace std;using LL = long long;template<class T>constexpr T power(T a, LL b) {T res {1};for (; b; b /= 2, a *= a) {if (b % 2) {res *= a;}}return res;}constexpr LL mul(LL a, LL b, LL p) {LL res = a * b - LL(1.L * a * b / p) * p;res %= p;if (res < 0) {res += p;}return res;}template<LL P>struct MInt {LL x;constexpr MInt() : x {0} {}constexpr MInt(LL x) : x {norm(x % getMod())} {}static LL Mod;constexpr static LL getMod() {if (P > 0) {return P;} else {return Mod;}}constexpr static void setMod(LL Mod_) {Mod = Mod_;}constexpr LL norm(LL x) const {if (x < 0) {x += getMod();}if (x >= getMod()) {x -= getMod();}return x;}constexpr LL val() const {return x;}constexpr MInt operator-() const {MInt res;res.x = norm(getMod() - x);return res;}constexpr MInt inv() const {return power(*this, getMod() - 2);}constexpr MInt &operator*=(MInt rhs) & {if (getMod() < (1ULL << 31)) {x = x * rhs.x % int(getMod());} else {x = mul(x, rhs.x, getMod());}return *this;}constexpr MInt &operator+=(MInt rhs) & {x = norm(x + rhs.x);return *this;}constexpr MInt &operator-=(MInt rhs) & {x = norm(x - rhs.x);return *this;}constexpr MInt &operator/=(MInt rhs) & {return *this *= rhs.inv();}friend constexpr MInt operator*(MInt lhs, MInt rhs) {MInt res = lhs;res *= rhs;return res;}friend constexpr MInt operator+(MInt lhs, MInt rhs) {MInt res = lhs;res += rhs;return res;}friend constexpr MInt operator-(MInt lhs, MInt rhs) {MInt res = lhs;res -= rhs;return res;}friend constexpr MInt operator/(MInt lhs, MInt rhs) {MInt res = lhs;res /= rhs;return res;}friend constexpr std::istream &operator>>(std::istream &is, MInt &a) {LL v;is >> v;a = MInt(v);return is;}friend constexpr std::ostream &operator<<(std::ostream &os, const MInt &a) {return os << a.val();}friend constexpr bool operator==(MInt lhs, MInt rhs) {return lhs.val() == rhs.val();}friend constexpr bool operator!=(MInt lhs, MInt rhs) {return lhs.val() != rhs.val();}friend constexpr bool operator<(MInt lhs, MInt rhs) {return lhs.val() < rhs.val();}};template<>LL MInt<0>::Mod = 998244353;constexpr int P = 998244353;using Z = MInt<P>;const int mxn = 2e5 + 10;int a[mxn];void solve() {int n, k;Z res = 1;cin >> n >> k;{Z cur = 1;for (int i = 1; i <= n; ++i) {cin >> a[i];cur *= k;res *= cur - 1;}}{LL tot = 0;for (int i = 1; i <= n; ++i)tot += 1ll * i * (a[i] - 1);res *= power(Z(k), tot);}cout << res << '\n';}int main() {int TestCase;for (scanf("%d", &TestCase); TestCase--;) solve();return 0;}// f(x + y) - f(x + y - 1) = f(x)f(y)// k^{M-c}(k-1)^c