QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#500799 | #6407. Classical A+B Problem | ucup-team2307# | WA | 6ms | 11644kb | C++17 | 3.1kb | 2024-08-01 20:48:02 | 2024-08-01 20:48:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const ll mod = (119 << 23) + 1, root = 62; // = 998244353
ll modpow(ll b, ll e) {
ll ans = 1;
for (; e; b = b * b % mod, e /= 2)
if (e & 1) ans = ans * b % mod;
return ans;
}
// For p < 2^30 there is also e.g. 5 << 25, 7 << 26, 479 << 21
// and 483 << 21 (same root). The last two are > 10^9.
typedef vector<ll> vl;
void ntt(vl &a) {
int n = sz(a), L = 31 - __builtin_clz(n);
static vl rt(2, 1);
for (static int k = 2, s = 2; k < n; k *= 2, s++) {
rt.resize(n);
ll z[] = {1, modpow(root, mod >> s)};
rep(i,k,2*k) rt[i] = rt[i / 2] * z[i & 1] % mod;
}
vi rev(n);
rep(i,0,n) rev[i] = (rev[i / 2] | (i & 1) << L) / 2;
rep(i,0,n) if (i < rev[i]) swap(a[i], a[rev[i]]);
for (int k = 1; k < n; k *= 2)
for (int i = 0; i < n; i += 2 * k) rep(j,0,k) {
ll z = rt[j + k] * a[i + j + k] % mod, &ai = a[i + j];
a[i + j + k] = ai - z + (z > ai ? mod : 0);
ai += (ai + z >= mod ? z - mod : z);
}
}
vl conv(const vl &a, const vl &b) {
if (a.empty() || b.empty()) return {};
int s = sz(a) + sz(b) - 1, B = 32 - __builtin_clz(s),
n = 1 << B;
int inv = modpow(n, mod - 2);
vl L(a), R(b), out(n);
L.resize(n), R.resize(n);
ntt(L), ntt(R);
rep(i,0,n)
out[-i & (n - 1)] = (ll)L[i] * R[i] % mod * inv % mod;
ntt(out);
return {out.begin(), out.begin() + s};
}
const int N = 1e6 + 66;
int fact[N], ifact[N];
void calc() {
ifact[0] = fact[0] = ifact[1] = 1;
for(int i = 2; i < N; i++) {
ifact[i] = mod - (mod / i) * 1ll * ifact[mod % i] % mod;
}
for(int i = 1; i < N; i++) {
fact[i] = fact[i - 1] * 1ll * i % mod;
ifact[i] = ifact[i - 1] * 1ll * ifact[i] % mod;
}
}
int nck(int n, int k) {
if(k < 0 || k > n) return 0;
int ans = fact[n] * 1ll * ifact[k] % mod;
return ans * 1ll * ifact[n-k]%mod;
}
int bp(int a, int p) {
int r = 1;
for(; p; p>>=1, a = a*1ll*a%mod)
if(p&1) r = r*1ll*a%mod;
return r;
}
vl solve(vl &a, int l, int r) {
if(l + 1 == r) {
return {1, a[l]};
}
int m = (l + r) / 2;
auto x = solve(a, l, m);
auto y = solve(a, m, r);
return conv(x, y);
}
vl stirling(int k, int N) {
vl a(N + 1); for(int i = 1; i <= N; i++) a[i] = ifact[i] * 1ll * fact[i - 1] % mod;
// a = polynomials::pow(a, k, n + 1);
vl res {1};
for(int t = k; t;) {
if(t & 1) res = conv(res, a);
res.resize(N + 1);
a = conv(a, a);
a.resize(N + 1);
t >>=1;
}
a = res;
ll ik = ifact[k] * 1ll * fact[k-1]%mod;
for(auto &i : a) i = i * 1ll * ik % mod;
for(int i = 0; i <= N; i++) a[i] = a[i] * 1ll* fact[i] % mod;
return a;
}
main() {
cin.tie(0)->sync_with_stdio(0);
calc();
vl x {1, 2, 3};
for(int k = 1; k <= 10; k++) {
auto y = stirling(k, 10);
for(auto i : y) cout << i << " ";
cout << endl;
}
}/*
2 piles sum <= 2
0 0
0 1
0 2
1 1
*/
詳細信息
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 11644kb
input:
6 2 786 1332 89110 2333333 10000000000000000000000000001
output:
0 1 1 2 6 24 120 720 5040 40320 362880 0 0 1 3 11 50 274 1764 13068 109584 1026576 0 0 0 2 12 70 450 3248 26264 236248 2345400 0 0 0 0 6 60 510 4410 40614 403704 4342080 0 0 0 0 0 24 360 4200 47040 538776 6463800 0 0 0 0 0 0 120 2520 38640 544320 7592760 0 0 0 0 0 0 0 720 20160 393120 6804000 ...
result:
wrong answer Token parameter [name=x] equals to "0", doesn't correspond to pattern "[1-9]{1,1}" (test case 1)