提出 #17633994


ソースコード 拡げる

import java.io.*; import java.util.*;
public class Main {
    static int MOD=998244353;
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        int N=Integer.parseInt(st.nextToken());
        int K=Integer.parseInt(st.nextToken());
        long[] a=new long[N];
        long[] p=new long[N]; //Only track p[.][i]
        long[] ps=new long[K+1];
        ps[0]=N;
        st=new StringTokenizer(br.readLine());
        for (int i = 0; i < N; i++) {
            a[i]=Integer.parseInt(st.nextToken());
            
        }
        Arrays.fill(p,1);
        for (int i = 1; i <=K; i++) {
            for (int j = 0; j < N; j++) {
                p[j]*=a[j]; p[j]%=MOD;
                ps[i]+=p[j]; ps[i]%=MOD;
            }
        }
        
        //System.out.println(Arrays.toString(pi));
        
        long ans; long cur=0;
        for (int X = 1; X <=K; X++) {//Evaluating answer for X=i
            ans=0; long binom=1;
            for (int i = 0; i <= (X-1)/2; i++) {
                cur=ps[i]*ps[X-i]; cur%=MOD;
                cur-=ps[X]; cur%=MOD;
                cur*=binom; cur%=MOD;
                ans+=cur; ans%=MOD;
                binom*=(X-i); binom%=MOD;
                binom*=inv(i+1,MOD); binom%=MOD;
            }
            if(X%2==0){
                cur=ps[X/2]*ps[X/2]; cur%=MOD;
                cur-=ps[X]; cur%=MOD;
                
                cur*=binom; cur%=MOD;
                cur*=inv(2,MOD); cur%=MOD;
                
                ans+=cur; ans%=MOD;
            }
            if(ans<0){
                ans+=MOD;
            }
            System.out.println(ans);
        }
    }
    public static long inv(long a, long b){//Computes modular inverse of a mod b
        //Assume b>a and gcd(a,b)=1, 
        if(a==1)return 1;
        long q=b/a;
        long r=b-q*a;
        long y=-inv(r,a);
        return ((b*y+1)/a)+b;
        
    }
}
  

提出情報

提出日時
問題 D - Powers
ユーザ CycloPolys
言語 Java (OpenJDK 1.8.0)
得点 600
コード長 2116 Byte
結果 AC
実行時間 1373 ms
メモリ 57084 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 3
AC × 30
セット名 テストケース
Sample 00_sample_01, 00_sample_02, 00_sample_03
All 00_sample_01, 00_sample_02, 00_sample_03, 10_small_01, 10_small_02, 10_small_03, 10_small_04, 10_small_05, 10_small_06, 10_small_07, 10_small_08, 10_small_09, 10_small_10, 20_random_01, 20_random_02, 20_random_03, 20_random_04, 20_random_05, 20_random_06, 20_random_07, 20_random_08, 20_random_09, 20_random_10, 30_max_01, 30_max_02, 30_max_03, 30_max_04, 30_max_05, 31_max_01, 31_max_02
ケース名 結果 実行時間 メモリ
00_sample_01 AC 72 ms 25024 KiB
00_sample_02 AC 66 ms 25128 KiB
00_sample_03 AC 68 ms 25184 KiB
10_small_01 AC 94 ms 26384 KiB
10_small_02 AC 96 ms 26596 KiB
10_small_03 AC 89 ms 26596 KiB
10_small_04 AC 153 ms 26320 KiB
10_small_05 AC 114 ms 25228 KiB
10_small_06 AC 93 ms 26436 KiB
10_small_07 AC 66 ms 25128 KiB
10_small_08 AC 76 ms 25556 KiB
10_small_09 AC 74 ms 25416 KiB
10_small_10 AC 82 ms 26228 KiB
20_random_01 AC 501 ms 38872 KiB
20_random_02 AC 570 ms 39864 KiB
20_random_03 AC 161 ms 32764 KiB
20_random_04 AC 596 ms 41252 KiB
20_random_05 AC 362 ms 50524 KiB
20_random_06 AC 881 ms 49196 KiB
20_random_07 AC 407 ms 40712 KiB
20_random_08 AC 808 ms 48944 KiB
20_random_09 AC 256 ms 49924 KiB
20_random_10 AC 405 ms 50232 KiB
30_max_01 AC 1346 ms 50572 KiB
30_max_02 AC 1357 ms 50524 KiB
30_max_03 AC 1370 ms 50576 KiB
30_max_04 AC 1364 ms 51460 KiB
30_max_05 AC 1336 ms 51332 KiB
31_max_01 AC 1276 ms 57084 KiB
31_max_02 AC 1373 ms 50732 KiB