QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#591830#7079. ArrayAfterlife#WA 370ms38856kbC++201.7kb2024-09-26 18:13:532024-09-26 18:13:54

Judging History

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

  • [2024-09-26 18:13:54]
  • 评测
  • 测评结果:WA
  • 用时:370ms
  • 内存:38856kb
  • [2024-09-26 18:13:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int mod ;
const int N = 3000;
int c[N + 5][N + 5];
int f1[N + 5] , f2[N + 5];
int g[N + 5] , h[N + 5];
int t[N + 5];
int qpow(int a,int b) {
    int ans = 1;
    while(b) {
        if(b &  1) ans = 1LL * ans * a %mod;
        a = 1LL * a * a %mod ; b >>= 1;
    }
    return ans;
}

void init() {
    int r2 = (mod + 1) / 2;
    for(int i = 0;i <= N;i++) {
        c[i][0] = 1;
        for(int j = 1;j <= i;j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
    }
    t[0] = 1;
    for(int i = 1;i <= N;i++) t[i] = 1LL * t[i - 1] * i % mod;

    for(int i = 1;i <= N;i++) {
        if(i == 1) {
            f1[1] = 1 ; f2[1] = 0;
        }
        else {
            f1[i] = qpow(i , i - 2) ;
            for(int j = 3;j < i;j++) {
                int num = 1LL * c[i][j] * j % mod * qpow(i , i - (j - 1) - 2) % mod * t[j - 1] % mod * r2 % mod;
                f1[i] = (f1[i] + num) % mod;
                f2[i] = (f2[i] + 1LL * num * j)  % mod;
            }
            if(i >= 3) {
                f1[i] = (f1[i] + 1LL * r2 * t[i - 1]) % mod ; /// big circle
                f2[i] = (f2[i] + 1LL * t[i - 1] * i % mod * r2 ) % mod;
            }
        }
    }
    g[0] = 1 ; h[0] = 0;
    for(int i = 1;i <= N;i++) {
        for(int j = 1;j <= i;j++) {
            g[i] = (g[i] + 1LL * c[i-1][j-1] * f1[i] % mod * g[i - j]) % mod;
            h[i] = (h[i] + 1LL * c[i-1][j-1] * ((1LL*f2[j]*g[i-j] + 1LL*f1[j]*h[i-j]) % mod)) % mod;
        }
    }
    return ;
}
void solv() {
    int n ; cin >> n;
    cout << h[n] << '\n';
}
int main() {
    ios::sync_with_stdio(false) ; cin.tie(0) ;
    int t;cin >> t >> mod;
    init() ;
    while(t--) solv() ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 370ms
memory: 38856kb

input:

1
4
1 2 3 4

output:

0

result:

wrong answer 1st words differ - expected: '22', found: '0'