結果

問題 No.1645 AB's abs
ユーザー tentententen
提出日時 2024-04-24 13:46:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 1,807 bytes
コンパイル時間 2,394 ms
コンパイル使用メモリ 79,016 KB
実行使用メモリ 40,824 KB
最終ジャッジ日時 2024-04-24 13:46:26
合計ジャッジ時間 6,669 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
36,824 KB
testcase_01 AC 51 ms
37,100 KB
testcase_02 AC 55 ms
37,120 KB
testcase_03 AC 52 ms
36,560 KB
testcase_04 AC 52 ms
37,112 KB
testcase_05 AC 51 ms
36,984 KB
testcase_06 AC 52 ms
36,560 KB
testcase_07 AC 52 ms
36,972 KB
testcase_08 AC 56 ms
37,084 KB
testcase_09 AC 58 ms
37,312 KB
testcase_10 AC 56 ms
37,044 KB
testcase_11 AC 58 ms
36,964 KB
testcase_12 AC 56 ms
36,924 KB
testcase_13 AC 87 ms
39,348 KB
testcase_14 AC 71 ms
38,384 KB
testcase_15 AC 88 ms
39,060 KB
testcase_16 AC 88 ms
39,436 KB
testcase_17 AC 86 ms
39,084 KB
testcase_18 AC 84 ms
38,600 KB
testcase_19 AC 85 ms
38,920 KB
testcase_20 AC 69 ms
38,512 KB
testcase_21 AC 84 ms
38,840 KB
testcase_22 AC 85 ms
38,828 KB
testcase_23 AC 88 ms
39,200 KB
testcase_24 AC 85 ms
38,992 KB
testcase_25 AC 84 ms
39,324 KB
testcase_26 AC 87 ms
38,968 KB
testcase_27 AC 88 ms
39,384 KB
testcase_28 AC 86 ms
38,700 KB
testcase_29 AC 86 ms
39,152 KB
testcase_30 AC 87 ms
39,120 KB
testcase_31 AC 88 ms
39,152 KB
testcase_32 AC 85 ms
39,312 KB
testcase_33 AC 86 ms
40,644 KB
testcase_34 AC 86 ms
40,264 KB
testcase_35 AC 96 ms
40,240 KB
testcase_36 AC 85 ms
40,356 KB
testcase_37 AC 93 ms
40,436 KB
testcase_38 AC 88 ms
40,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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[] counts = new int[1];
        counts[0] = 1;
        int max = 0;
        while (n-- > 0) {
            int x = sc.nextInt();
            int[] next = new int[max + x + 1];
            for (int i = 0; i <= max; i++) {
                next[i + x] += counts[i];
                next[i + x] %= MOD;
                next[Math.abs(i - x)] += counts[i];
                next[Math.abs(i - x)] %= MOD;
            }
            counts = next;
            max += x;
        }
        long ans = 0;
        for (int i = 1; i < counts.length; i++) {
            ans += (long)counts[i] * i % MOD;
            ans %= MOD;
        }
        System.out.println(ans);
    }
}
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();
        }
    }
    
}
0