QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#251781 | #7774. 基础寄术练习题 | hos_lyric# | 25 | 1ms | 3920kb | C++14 | 5.3kb | 2023-11-15 08:20:41 | 2024-07-04 02:25:17 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
////////////////////////////////////////////////////////////////////////////////
// Barrett
struct ModInt {
static unsigned M;
static unsigned long long NEG_INV_M;
static void setM(unsigned m) { M = m; NEG_INV_M = -1ULL / M; }
unsigned x;
ModInt() : x(0U) {}
ModInt(unsigned x_) : x(x_ % M) {}
ModInt(unsigned long long x_) : x(x_ % M) {}
ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) {
const unsigned long long y = static_cast<unsigned long long>(x) * a.x;
const unsigned long long q = static_cast<unsigned long long>((static_cast<unsigned __int128>(NEG_INV_M) * y) >> 64);
const unsigned long long r = y - M * q;
x = r - M * (r >= M);
return *this;
}
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
unsigned a = M, b = x; int y = 0, z = 1;
for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
assert(a == 1U); return ModInt(y);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
unsigned ModInt::M;
unsigned long long ModInt::NEG_INV_M;
// !!!Use ModInt::setM!!!
////////////////////////////////////////////////////////////////////////////////
using Mint = ModInt;
constexpr int LIM_INV = 1010;
Mint inv[LIM_INV], fac[LIM_INV], invFac[LIM_INV];
void prepare() {
inv[1] = 1;
for (int i = 2; i < LIM_INV; ++i) {
inv[i] = -((Mint::M / i) * inv[Mint::M % i]);
}
fac[0] = invFac[0] = 1;
for (int i = 1; i < LIM_INV; ++i) {
fac[i] = fac[i - 1] * i;
invFac[i] = invFac[i - 1] * inv[i];
}
}
Mint binom(Int n, Int k) {
if (n < 0) {
if (k >= 0) {
return ((k & 1) ? -1 : +1) * binom(-n + k - 1, k);
} else if (n - k >= 0) {
return (((n - k) & 1) ? -1 : +1) * binom(-k - 1, n - k);
} else {
return 0;
}
} else {
if (0 <= k && k <= n) {
assert(n < LIM_INV);
return fac[n] * invFac[k] * invFac[n - k];
} else {
return 0;
}
}
}
int N, M, K, MO;
int main() {
for (; ~scanf("%d%d%d%d", &N, &M, &K, &MO); ) {
Mint::setM(MO);
prepare();
Mint ans = 0;
if (K == 1) {
vector<Mint> fs(M + 1, 0);
fs[0] = 1;
for (int a = 1; a <= M; ++a) {
for (int i = a; --i >= 0; ) {
fs[i + 1] += fs[i] * inv[a];
}
}
ans = fs[N];
} else if (K == 2) {
} else {
assert(false);
}
printf("%u\n", ans.x);
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 1ms
memory: 3824kb
input:
9 16 1 327134593
output:
162102742
result:
ok single line: '162102742'
Test #2:
score: 10
Accepted
time: 0ms
memory: 3836kb
input:
11 18 1 834359503
output:
256188485
result:
ok single line: '256188485'
Test #3:
score: 10
Accepted
time: 1ms
memory: 3780kb
input:
18 18 1 614802701
output:
552168146
result:
ok single line: '552168146'
Test #4:
score: 0
Wrong Answer
time: 1ms
memory: 3728kb
input:
7 16 2 861918403
output:
0
result:
wrong answer 1st lines differ - expected: '306693876', found: '0'
Subtask #2:
score: 25
Accepted
Test #6:
score: 25
Accepted
time: 1ms
memory: 3836kb
input:
60 98 1 715015339
output:
690737273
result:
ok single line: '690737273'
Test #7:
score: 25
Accepted
time: 1ms
memory: 3792kb
input:
96 97 1 507892589
output:
481151247
result:
ok single line: '481151247'
Test #8:
score: 25
Accepted
time: 1ms
memory: 3920kb
input:
90 95 1 621080027
output:
255353202
result:
ok single line: '255353202'
Test #9:
score: 25
Accepted
time: 0ms
memory: 3744kb
input:
85 94 1 297115421
output:
122254364
result:
ok single line: '122254364'
Test #10:
score: 25
Accepted
time: 0ms
memory: 3908kb
input:
81 91 1 460412027
output:
148037986
result:
ok single line: '148037986'
Subtask #3:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 0ms
memory: 3812kb
input:
29 29 2 545875273
output:
0
result:
wrong answer 1st lines differ - expected: '171843225', found: '0'
Subtask #4:
score: 0
Wrong Answer
Test #16:
score: 0
Wrong Answer
time: 0ms
memory: 3744kb
input:
27 30 2 360712453
output:
0
result:
wrong answer 1st lines differ - expected: '80987914', found: '0'
Subtask #5:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 0ms
memory: 3816kb
input:
29 38 2 909155077
output:
0
result:
wrong answer 1st lines differ - expected: '745973305', found: '0'
Subtask #6:
score: 0
Wrong Answer
Test #26:
score: 0
Wrong Answer
time: 1ms
memory: 3836kb
input:
57 66 2 767174999
output:
0
result:
wrong answer 1st lines differ - expected: '315351738', found: '0'
Subtask #7:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 0ms
memory: 3844kb
input:
96 96 2 453296971
output:
0
result:
wrong answer 1st lines differ - expected: '222864385', found: '0'