結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー tentententen
提出日時 2023-03-16 14:37:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 326 ms / 2,000 ms
コード長 2,235 bytes
コンパイル時間 4,463 ms
コンパイル使用メモリ 88,676 KB
実行使用メモリ 58,372 KB
最終ジャッジ日時 2023-10-18 13:01:34
合計ジャッジ時間 8,066 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
53,548 KB
testcase_01 AC 54 ms
53,488 KB
testcase_02 AC 54 ms
53,544 KB
testcase_03 AC 54 ms
53,544 KB
testcase_04 AC 54 ms
53,544 KB
testcase_05 AC 54 ms
53,536 KB
testcase_06 AC 54 ms
53,544 KB
testcase_07 AC 53 ms
52,476 KB
testcase_08 AC 204 ms
56,144 KB
testcase_09 AC 56 ms
53,544 KB
testcase_10 AC 319 ms
57,200 KB
testcase_11 AC 167 ms
55,988 KB
testcase_12 AC 164 ms
56,216 KB
testcase_13 AC 169 ms
56,144 KB
testcase_14 AC 179 ms
56,152 KB
testcase_15 AC 260 ms
58,372 KB
testcase_16 AC 158 ms
55,980 KB
testcase_17 AC 176 ms
56,052 KB
testcase_18 AC 233 ms
57,080 KB
testcase_19 AC 177 ms
56,060 KB
testcase_20 AC 55 ms
52,856 KB
testcase_21 AC 215 ms
56,352 KB
testcase_22 AC 56 ms
52,860 KB
testcase_23 AC 55 ms
52,860 KB
testcase_24 AC 54 ms
52,864 KB
testcase_25 AC 326 ms
56,712 KB
testcase_26 AC 303 ms
58,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int q = sc.nextInt();
        long[] current = new long[n + 1];
        current[0] = 1;
        long[] next = new long[n + 1];
        for (int i = 1; i <= n; i++) {
            int x = sc.nextInt();
            for (int j = 1; j <= i; j++) {
                next[j] = current[j - 1];
            }
            for (int j = 0; j < i; j++) {
                next[j] += current[j] * (x - 1) % MOD;
                next[j] %= MOD;
            }
            long[] tmp = current;
            current = next;
            next = tmp;
            Arrays.fill(next, 0);
        }
        StringBuilder sb = new StringBuilder();
        while (q-- > 0) {
            sb.append(current[sc.nextInt()]).append("\n");
        }
        System.out.print(sb);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0