QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#500801#6407. Classical A+B Problemucup-team2307#WA 7ms11436kbC++173.0kb2024-08-01 20:49:062024-08-01 20:49:06

Judging History

你现在查看的是最新测评结果

  • [2024-08-01 20:49:06]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:11436kb
  • [2024-08-01 20:49:06]
  • 提交

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];
    // 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;
    
    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: 7ms
memory: 11436kb

input:

6
2
786
1332
89110
2333333
10000000000000000000000000001

output:

0 1 1 1 1 1 1 1 1 1 1 
0 0 2 6 14 30 62 126 254 510 1022 
0 0 0 6 36 150 540 1806 5796 18150 55980 
0 0 0 0 24 240 1560 8400 40824 186480 818520 
0 0 0 0 0 120 1800 16800 126000 834120 5103000 
0 0 0 0 0 0 720 15120 191520 1905120 16435440 
0 0 0 0 0 0 0 5040 141120 2328480 29635200 
0 0 0 0 0 0 0 0...

result:

wrong answer Token parameter [name=x] equals to "0", doesn't correspond to pattern "[1-9]{1,1}" (test case 1)