結果

問題 No.1645 AB's abs
ユーザー tentententen
提出日時 2023-02-22 10:38:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 2,154 bytes
コンパイル時間 3,410 ms
コンパイル使用メモリ 87,368 KB
実行使用メモリ 61,220 KB
最終ジャッジ日時 2023-09-29 19:25:45
合計ジャッジ時間 8,175 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,428 KB
testcase_01 AC 42 ms
49,456 KB
testcase_02 AC 45 ms
49,820 KB
testcase_03 AC 41 ms
49,808 KB
testcase_04 AC 42 ms
49,432 KB
testcase_05 AC 42 ms
49,340 KB
testcase_06 AC 42 ms
49,648 KB
testcase_07 AC 41 ms
49,416 KB
testcase_08 AC 49 ms
49,576 KB
testcase_09 AC 53 ms
50,720 KB
testcase_10 AC 47 ms
49,748 KB
testcase_11 AC 50 ms
50,448 KB
testcase_12 AC 47 ms
50,232 KB
testcase_13 AC 70 ms
60,832 KB
testcase_14 AC 75 ms
56,492 KB
testcase_15 AC 76 ms
60,916 KB
testcase_16 AC 70 ms
56,484 KB
testcase_17 AC 72 ms
61,220 KB
testcase_18 AC 69 ms
56,440 KB
testcase_19 AC 72 ms
60,904 KB
testcase_20 AC 75 ms
56,460 KB
testcase_21 AC 67 ms
56,576 KB
testcase_22 AC 76 ms
60,936 KB
testcase_23 AC 69 ms
61,124 KB
testcase_24 AC 72 ms
61,156 KB
testcase_25 AC 77 ms
61,068 KB
testcase_26 AC 73 ms
60,904 KB
testcase_27 AC 74 ms
60,924 KB
testcase_28 AC 72 ms
60,792 KB
testcase_29 AC 81 ms
61,220 KB
testcase_30 AC 74 ms
61,124 KB
testcase_31 AC 71 ms
61,112 KB
testcase_32 AC 71 ms
61,156 KB
testcase_33 AC 75 ms
60,864 KB
testcase_34 AC 74 ms
60,960 KB
testcase_35 AC 75 ms
61,124 KB
testcase_36 AC 75 ms
60,932 KB
testcase_37 AC 76 ms
60,892 KB
testcase_38 AC 73 ms
61,164 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 base = 100 * n + 10;
        int[][] dp = new int[n + 1][base * 2];
        int max = 0;
        dp[0][base] = 1;
        for (int i = 1; i <= n; i++) {
            int x = sc.nextInt();
            for (int j = base - max; j <= base + max; j++) {
                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;
            }
            max += x;
        }
        long ans = 0;
        for (int i = 0; i < dp[n].length; i++) {
            ans += (long)dp[n][i] * Math.abs(i - base) % MOD;
            ans %= MOD;
        }
        System.out.println(ans);
    }
}
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