結果

問題 No.1645 AB's abs
ユーザー tentententen
提出日時 2021-08-16 14:58:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 1,536 bytes
コンパイル時間 2,846 ms
コンパイル使用メモリ 77,712 KB
実行使用メモリ 54,840 KB
最終ジャッジ日時 2024-04-17 17:47:53
合計ジャッジ時間 7,342 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
37,184 KB
testcase_01 AC 55 ms
36,916 KB
testcase_02 AC 64 ms
38,976 KB
testcase_03 AC 52 ms
36,988 KB
testcase_04 AC 52 ms
37,168 KB
testcase_05 AC 52 ms
37,044 KB
testcase_06 AC 55 ms
37,292 KB
testcase_07 AC 54 ms
37,300 KB
testcase_08 AC 68 ms
39,764 KB
testcase_09 AC 68 ms
40,072 KB
testcase_10 AC 67 ms
39,596 KB
testcase_11 AC 67 ms
39,592 KB
testcase_12 AC 68 ms
39,088 KB
testcase_13 AC 101 ms
53,896 KB
testcase_14 AC 97 ms
53,688 KB
testcase_15 AC 97 ms
54,196 KB
testcase_16 AC 98 ms
53,556 KB
testcase_17 AC 100 ms
53,832 KB
testcase_18 AC 99 ms
53,728 KB
testcase_19 AC 101 ms
53,804 KB
testcase_20 AC 101 ms
54,040 KB
testcase_21 AC 100 ms
53,952 KB
testcase_22 AC 104 ms
53,940 KB
testcase_23 AC 101 ms
54,676 KB
testcase_24 AC 102 ms
54,392 KB
testcase_25 AC 100 ms
54,620 KB
testcase_26 AC 103 ms
54,792 KB
testcase_27 AC 101 ms
54,756 KB
testcase_28 AC 103 ms
54,656 KB
testcase_29 AC 105 ms
54,696 KB
testcase_30 AC 102 ms
54,800 KB
testcase_31 AC 102 ms
54,840 KB
testcase_32 AC 103 ms
54,428 KB
testcase_33 AC 102 ms
54,728 KB
testcase_34 AC 102 ms
54,832 KB
testcase_35 AC 105 ms
54,688 KB
testcase_36 AC 102 ms
54,536 KB
testcase_37 AC 103 ms
54,596 KB
testcase_38 AC 101 ms
54,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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 base = n * 100;
        long[][] dp = new long[n + 1][base * 2 + 1];
        dp[0][base] = 1;
        for (int i = 1; i <= n; i++) {
            int x = sc.nextInt();
            for (int j = 0; j < dp[i].length; j++) {
                if (dp[i - 1][j] > 0) {
                    dp[i][j + x] += dp[i - 1][j];
                    dp[i][j + x] %= MOD;
                    dp[i][j - x] += dp[i - 1][j];
                    dp[i][j + x] %= MOD;
                }
            }
        }
        long ans = 0;
        for (int i = 0; i < dp[n].length; i++) {
            long value = Math.abs(i - base);
            ans += value * dp[n][i] % MOD;
            ans %= MOD;
        }
        System.out.println(ans);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0