結果
問題 | No.2807 Have Another Go (Easy) |
ユーザー |
![]() |
提出日時 | 2024-07-17 11:20:22 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 235 ms / 3,000 ms |
コード長 | 2,194 bytes |
コンパイル時間 | 2,962 ms |
コンパイル使用メモリ | 88,532 KB |
実行使用メモリ | 71,640 KB |
最終ジャッジ日時 | 2024-07-17 11:20:35 |
合計ジャッジ時間 | 12,591 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 46 |
ソースコード
import java.io.*;import java.util.*;import java.util.function.*;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 m = sc.nextInt();int k = sc.nextInt();long[] dp = new long[n * 2 + 7];dp[0] = 1;for (int i = 0; i < n * 2; i++) {for (int j = 1; j <= 6; j++) {dp[i + j] += dp[i];dp[i + j] %= MOD;}}long[] fp = new long[n * 2 + 7];for (int i = 0; i < 6; i++) {fp[n * 2 + i] = 1;}for (int i = n * 2 + 5; i > 0; i--) {for (int j = 1; j <= 6; j++) {if (i - j >= 0 && i - j < n * 2) {fp[i - j] += fp[i];fp[i - j] %= MOD;}}}String result = IntStream.range(0, k).mapToObj(i -> {int x = sc.nextInt();long ans = ((dp[x] * fp[x] % MOD + dp[x + n] * fp[x + n] % MOD) % MOD+ MOD - dp[x] * dp[n] % MOD * fp[x + n] % MOD) % MOD;return String.valueOf(ans);}).collect(Collectors.joining("\n"));System.out.println(result);}}class Scanner {BufferedReader br;StringTokenizer st = new StringTokenizer("");StringBuilder sb = new StringBuilder();public Scanner() {try {br = new BufferedReader(new InputStreamReader(System.in));} catch (Exception e) {}}public int nextInt() {return Integer.parseInt(next());}public long nextLong() {return Long.parseLong(next());}public double nextDouble() {return Double.parseDouble(next());}public String next() {try {while (!st.hasMoreTokens()) {st = new StringTokenizer(br.readLine());}} catch (Exception e) {e.printStackTrace();} finally {return st.nextToken();}}}