QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#132495#6417. Classical Summation Problemcciafrino#WA 1ms3476kbC++142.5kb2023-07-30 00:42:002023-07-30 00:42:01

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-30 00:42:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3476kb
  • [2023-07-30 00:42:00]
  • 提交

answer

#include<bits/stdc++.h>
namespace std {
template<unsigned M_> struct modnum {
    static constexpr unsigned M = M_;
    using ll = long long; using ull = unsigned long long;
    unsigned x;
    constexpr modnum() : x(0U) {}
    constexpr modnum(int a) : x(((a %= static_cast<int>(M)) < 0) ? (a + static_cast<int>(M)) : a) {}
    constexpr modnum(unsigned a) : x(a%M) {}
    constexpr modnum(ll a) : x(((a %= static_cast<ll>(M)) < 0) ? (a + static_cast<ll>(M)) : a) {}
    explicit operator int() const { return x; }
    modnum& operator +=(const modnum& a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
    modnum& operator -=(const modnum& a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
    modnum& operator *=(const modnum& a) { x = unsigned((static_cast<ull>(x) * a.x) % M); return *this; }
    modnum& operator /=(const modnum& a) { return (*this *= a.inv()); }
    modnum operator +(const modnum& a) const { return modnum(*this) += a; }
    modnum operator -(const modnum& a) const { return modnum(*this) -= a; }
    modnum operator *(const modnum& a) const { return modnum(*this) *= a; }
    modnum operator /(const modnum& a) const { return modnum(*this) /= a; }
    modnum operator +() const { return *this; }
    modnum operator -() const { modnum a; a.x = x ? (M-x) : 0U; return a; }
    modnum pow(ll e) const {
        modnum x2 = x, xe = 1U;
        for (; e; e >>= 1) {
            if (e & 1) xe *= x2;
            x2 *= x2;
        }
        return xe;
    }
    modnum inv() const {
        unsigned a = x, b = M; int y = 1, z = 0;
        while (a) {
            const unsigned q = (b/a), c = (b - q*a);
            b = a, a = c;
            const int w = z - static_cast<int>(q) * y;
            z = y, y = w;
        }
        return modnum(z);
    }
};
}
int main() {
    using namespace std;
    cin.tie(nullptr)->sync_with_stdio(false);
    int N, K; cin >> N >> K;
    using num = modnum<998244353>;
    if (K & 1) {
        cout << (num(N).pow(K) * num(N + 1) / 2).x << '\n';
    } else {
        num S = 0;
        for (int x = 0; x <= 2*N; ++x) {
            num cur = 0;
            if (2*x < N) {
                S += num(N).pow(K) - num(K).pow(K/2) * num(x).pow(K/2) * num(N-x).pow(K/2);
            } else {
                for (int i = 1; i < K/2; ++i) {
                    cur += num(K).pow(i) * num(x).pow(i) * num(N-x).pow(K-i);
                }
            }
            S += cur;
        }
        cout << S.x << '\n';
    }
}

详细

Test #1:

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

input:

3 2

output:

14

result:

ok 1 number(s): "14"

Test #2:

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

input:

5 3

output:

375

result:

ok 1 number(s): "375"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3372kb

input:

2 2

output:

4

result:

wrong answer 1st numbers differ - expected: '5', found: '4'