QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#499958#6551. Forever YoungpandapythonerWA 280ms34436kbC++233.0kb2024-07-31 20:30:352024-07-31 20:30:43

Judging History

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

  • [2024-07-31 20:30:43]
  • 评测
  • 测评结果:WA
  • 用时:280ms
  • 内存:34436kb
  • [2024-07-31 20:30:35]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;


#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, n) for(int i = 0; i < n; i += 1)
#define len(a) ((int)(a).size())


const ll inf = 1e18;
mt19937 rnd(234);
const ll mod = 998244353;


ll bin_pow(ll x, ll n) {
    assert(0 <= x and x < mod and n >= 0);
    ll rs = 1;
    for (ll i = 1, a = x; i <= n; i *= 2, a = a * a % mod) {
        if (n & i) {
            rs = rs * a % mod;
        }
    }
    return rs;
}


ll inv(ll x) {
    assert(x != 0);
    ll a = bin_pow(x, mod - 2);
    assert(a * x % mod == 1);
    return a;
}


int32_t main() {
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    int n; cin >> n;
    vector<int> a(n); rep(i, n) cin >> a[i];
    int m; cin >> m;
    vector<int> b(m); rep(i, m) cin >> b[i];
    ll k;
    cin >> k;
    auto get_dp = [&](vector<int> a) -> map<vector<int>, ll> {
        map<vector<int>, ll> dp;
        dp[a] = 1;
        queue<vector<int>> q;
        q.push(a);
        while (!q.empty()) {
            auto v = q.front();
            q.pop();
            ll val = dp[v];
            rep(i, len(v)) {
                assert(v[i] > 0);
                if (i + 1 < len(v) and v[i] == v[i + 1]) continue;
                auto to = v;
                to[i] -= 1;
                if (to.back() == 0) {
                    to.pop_back();
                }
                auto it = dp.find(to);
                if (it == dp.end()) {
                    dp[to] = dp[v];
                    q.push(to);
                } else {
                    it->second = (it->second + val);
                    if (it->second >= mod) {
                        it->second -= mod; 
                    }
                }
            }
            return dp;
        }
        };
    auto dpa = get_dp(a);
    auto dpb = get_dp(b);
    ll fsize = 2 * k + 1000;
    vector<ll> f(fsize + 1), invf(fsize + 1);
    f[0] = invf[0] = 1;
    for (int i = 1; i <= fsize; i += 1) {
        f[i] = (f[i - 1] * i) % mod;
        invf[i] = inv(f[i]);
    }
    ll sma = 0, smb = 0;
    rep(i, n) sma += a[i];
    rep(i, m) smb += b[i];
    ll inv2 = inv(2);
    ll result = 0;
    for (auto [v, vala] : dpa) {
        auto it = dpb.find(v);
        if (it == dpb.end()) continue;
        ll valb = it->second;
        ll msum = 0;
        rep(i, len(v)) msum += v[i];
        assert(msum <= sma and msum <= smb);
        ll down = sma - msum;
        ll up = smb - msum;
        if (down + up > k or (down + up) % 2 != k % 2) continue;
        ll coeff = f[down + up] * invf[down] % mod * invf[up] % mod;
        for (ll x = down + up; x < k; x += 2) {
            coeff = coeff * (x + 1) % mod * (x + 2) % mod * inv2 % mod;
        }
        coeff = coeff * invf[(k - down - up) / 2] % mod;
        result = (result + coeff * vala % mod * valb) % mod;
    }
    cout << result << "\n";
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3552kb

input:

3
3 2 1
3
3 2 1
2

output:

7

result:

ok 1 number(s): "7"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3884kb

input:

3
3 2 1
3
3 2 1
1111

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3668kb

input:

0

0

10

output:

945

result:

ok 1 number(s): "945"

Test #4:

score: -100
Wrong Answer
time: 280ms
memory: 34436kb

input:

10
10 9 8 7 6 5 4 4 4 3
10
10 9 8 7 6 5 4 4 4 3
1000000

output:

200470732

result:

wrong answer 1st numbers differ - expected: '591072522', found: '200470732'