結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー htensaihtensai
提出日時 2020-06-04 13:03:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 402 ms / 2,000 ms
コード長 719 bytes
コンパイル時間 3,219 ms
コンパイル使用メモリ 74,144 KB
実行使用メモリ 60,732 KB
最終ジャッジ日時 2023-08-19 03:28:14
合計ジャッジ時間 10,256 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
56,164 KB
testcase_01 AC 122 ms
55,820 KB
testcase_02 AC 123 ms
56,080 KB
testcase_03 AC 123 ms
54,144 KB
testcase_04 AC 121 ms
55,524 KB
testcase_05 AC 124 ms
55,508 KB
testcase_06 AC 123 ms
55,736 KB
testcase_07 AC 124 ms
56,068 KB
testcase_08 AC 353 ms
59,996 KB
testcase_09 AC 140 ms
56,088 KB
testcase_10 AC 402 ms
60,276 KB
testcase_11 AC 344 ms
60,156 KB
testcase_12 AC 332 ms
59,876 KB
testcase_13 AC 332 ms
60,732 KB
testcase_14 AC 273 ms
59,060 KB
testcase_15 AC 366 ms
60,240 KB
testcase_16 AC 260 ms
59,396 KB
testcase_17 AC 256 ms
59,032 KB
testcase_18 AC 365 ms
60,176 KB
testcase_19 AC 334 ms
60,408 KB
testcase_20 AC 135 ms
55,796 KB
testcase_21 AC 356 ms
60,352 KB
testcase_22 AC 135 ms
55,788 KB
testcase_23 AC 122 ms
55,696 KB
testcase_24 AC 124 ms
55,788 KB
testcase_25 AC 393 ms
60,192 KB
testcase_26 AC 347 ms
60,156 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