結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー htensaihtensai
提出日時 2020-06-04 13:03:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 411 ms / 2,000 ms
コード長 719 bytes
コンパイル時間 2,123 ms
コンパイル使用メモリ 77,068 KB
実行使用メモリ 47,764 KB
最終ジャッジ日時 2024-05-06 10:35:14
合計ジャッジ時間 9,089 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
41,384 KB
testcase_01 AC 119 ms
41,184 KB
testcase_02 AC 118 ms
41,164 KB
testcase_03 AC 108 ms
40,040 KB
testcase_04 AC 113 ms
41,228 KB
testcase_05 AC 113 ms
41,480 KB
testcase_06 AC 117 ms
41,216 KB
testcase_07 AC 116 ms
41,140 KB
testcase_08 AC 336 ms
47,024 KB
testcase_09 AC 127 ms
41,468 KB
testcase_10 AC 404 ms
47,764 KB
testcase_11 AC 277 ms
45,656 KB
testcase_12 AC 258 ms
45,684 KB
testcase_13 AC 254 ms
46,028 KB
testcase_14 AC 317 ms
47,116 KB
testcase_15 AC 388 ms
47,644 KB
testcase_16 AC 224 ms
44,652 KB
testcase_17 AC 252 ms
45,268 KB
testcase_18 AC 402 ms
47,760 KB
testcase_19 AC 260 ms
46,692 KB
testcase_20 AC 137 ms
41,596 KB
testcase_21 AC 335 ms
46,196 KB
testcase_22 AC 129 ms
41,828 KB
testcase_23 AC 105 ms
40,160 KB
testcase_24 AC 114 ms
41,320 KB
testcase_25 AC 411 ms
47,640 KB
testcase_26 AC 397 ms
47,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 998244353;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		int[] arr = new int[n + 1];
		for (int i = 1; i <= n; i++) {
		    arr[i] = sc.nextInt();
		}
		long[] dp = new long[n + 1];
		dp[0] = 1;
		for (int i = 1; i <= n; i++) {
		    for (int j = i;  j >= 1; j--) {
		        dp[j] = dp[j] * (arr[i] - 1) + dp[j - 1];
		        dp[j] %= MOD;
		    }
		    dp[0] = dp[0] * (arr[i] - 1);
		    dp[0] %= MOD;
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    sb.append(dp[sc.nextInt()]).append("\n");
		}
		System.out.print(sb);
	}
}
0