QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#566057#9317. RivalsAfterlifeWA 0ms15140kbC++203.6kb2024-09-15 22:57:042024-09-15 22:57:04

Judging History

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

  • [2024-09-15 22:57:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:15140kb
  • [2024-09-15 22:57:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, c;
int f[305][305][31];
int a[35];
void upd(int &x,int y) {
    ((x += y) >= mod ? (x -= mod) : 0);
}
int fpow(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;
}
int t[35] , rt[35];
int ans[305];
void calc(int p) {
    int sx = 0 , sy = 0 ,sz = 0;
    memset(f,0,sizeof(f));
    f[0][0][0] = 1;
    for(int i = 1;i <= n;i++) {
        for(int x = sx;x >=0 ; x--) {
            for(int y = sy;y >= 0;y--) {
                for(int z=sz;z >= 0;z--) {
                    if(!f[x][y][z]) continue ;
                    int d = f[x][y][z];
                    if(i == p) {
                        for(int k = a[i];k >= a[i];k--) {
                            upd(f[x + k][y + k][z] , 1LL * f[x][y][z] * rt[k] % mod) ;
                        }
                    }
                    else if(i <= c ) {
                        upd(f[x + a[i]][y + a[i]][z] , 1LL * f[x][y][z] * rt[a[i]] % mod) ;
                        upd(f[x][y + a[i]][z + 1] , f[x][y][z]) ;
                        for(int k = a[i];k >= 0;k--) {
                            upd(f[x + k][y + a[i]][z] , (mod - 1LL * f[x][y][z] * rt[k] % mod) % mod) ;
                        }
                    }
                    else {
                        upd(f[x][y + a[i]][z + 1] , f[x][y][z]) ;
                        for(int k = a[i];k >= 0;k--) {
                            upd(f[x + k][y + a[i]][z] , (mod - 1LL * f[x][y][z] * rt[k] % mod) % mod) ;
                            upd(f[x + k][y + k][z] , 1LL * f[x][y][z] * rt[k] % mod) ;
                        }
                    }
                    
                    f[x][y][z] = (f[x][y][z] - d + mod) % mod ;
                }
            }
        }
        sx += a[i];
        sy += a[i];
        sz += (i != p);
    }
    int rn = fpow(n , mod - 2);
    for(int i = 0;i <= sx;i++) {
        for(int j = 0;j <= sy;j++) {
            for(int k = 0;k <= sz;k++) {
                if(!f[i][j][k]) continue ;
                // if(j == 2) printf("f %d %d %d : %d\n",i,j,k,f[i][j][k]) ;
                /// [x^i * y^j * e^(xk)] , prob = 1/n * sum {[x^t](x^i * e^(xk) ) * t! / n^t}
                /// = 1/n * sum_{t >= 0} { k^t/t! * (t + i)! / n^(t+i) }
                if(k == 0) {
                    int sol = 1LL * rn * f[i][j][k] % mod;
                    sol = 1LL * sol * t[i] % mod * fpow(rn , i) % mod;
                    // printf("cont %d\n",sol);
                    ans[j + 1] = (ans[j + 1] + sol) % mod;
                }
                else {
                    int sol = 1LL * rn * f[i][j][k] % mod;
                    sol = 1LL * sol * t[i] % mod * n % mod ;
                    sol = 1LL * sol * fpow(fpow(n - k , mod - 2) , i + 1) % mod;
                    // printf("cont %d\n",sol);
                    ans[j + 1] = (ans[j + 1] + sol) % mod;
                }
            }
        }
    }
    // printf("---\n") ;
}
int main() {
    cin >> n>>c;
    int sn = 0;
    for(int i = 1;i <= n;i++) {cin >> a[i]; sn += a[i] ;}
    f[0][0][0] = 1;
    t[0] = rt[0] = 1;
    for(int i = 1;i <= max(n,10) ; i++) {
        t[i] = 1LL * t[i - 1] * i % mod;
        rt[i] = fpow(t[i] , mod - 2);
    }

    for(int i = 1;i <= c;i++) {
        a[i]-- ; calc(i) ;
        a[i]++ ;
    }
    for(int i = 1;i <= sn;i++) {
        ans[i] = (ans[i] + ans[i - 1]) % mod;
        printf("%d ",ans[i]) ; 
    }
    printf("\n");
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 15124kb

input:

5 3
1 1 1 1 1

output:

0 0 299473306 199648871 1 

result:

ok 5 tokens

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 15140kb

input:

8 5
3 5 3 2 2 5 4 4

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 851829480 341177770 353499418 975928140 538297451 705274690 575946976 208315404 594152940 587822837 350847000 617382889 576400883 1 

result:

wrong answer 16th words differ - expected: '293319617', found: '341177770'