跪求大佬帮忙调一下,样例过了全wa,给关注awa
查看原帖
跪求大佬帮忙调一下,样例过了全wa,给关注awa
685127
MaLX楼主2022/3/8 18:01
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define int long long
const int ni = 2e2, pi = 998244353;
int n, m, l, ai[ni], bi[ni];
int yi[ni], ci[ni];
void solve();
int ksn(int a), ksm(int a, int b);
signed main() {
    int t;
    scanf("%lld", &t);
    for (int i = 1; i <= t; i++) solve();
    return 0;
}
int charge(int k) {
    if (k <= m + 3)
        return yi[k];
    int ans = 0;  // printf("[|%lld|]",k);
    for (int i = 1; i <= m + 4; i++) {
        int res = yi[i];
        for (int j = 1; j <= m + 4; j++)
            if (j != i)
                (res *= (k - j) * ksn(i - j) % pi) %= pi;
        (ans += res) %= pi;
        // printf("<(%lld)>",res);
    }
    return ans;
}
void solve() {
    scanf("%lld%lld", &n, &m);
    int ans = 0;
    for (int i = 1; i <= m; i++) scanf("%lld", &ai[i]);
    sort(ai + 1, ai + 1 + m);
    for (int i = m; i >= 1; i--)
        if (n == ai[m])
            m--, n--;
        else
            break;
    for (int i = 1; i <= m + 4; i++) yi[i] = (yi[i - 1] + ksm(i, m + 1)) % pi;
    // for(int i=1;i<=m+1;i++)printf("<%lld>",yi[i]);
    for (int i = 0; i <= m; i++) {
        int res = charge(n - ai[i]);
        // printf("[%lld]",res);
        for (int j = i; j <= m; j++) (res += pi - ksm(ai[j] - ai[i], m + 1)) %= pi;
        (ans += res) %= pi;
    }
    printf("%lld\n", (ans + pi) % pi);
}
int ksn(int a) { return ksm(a, pi - 2); }
int ksm(int a, int b) {
    int c = 1;
    a %= pi;
    while (b) {
        if (b & 1)
            c = c * a % pi;
        a = a * a % pi;
        b >>= 1;
    }
    return c;
}

2022/3/8 18:01
加载中...