結果

問題 No.1645 AB's abs
ユーザー tentententen
提出日時 2022-09-29 10:07:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,659 bytes
コンパイル時間 3,344 ms
コンパイル使用メモリ 74,384 KB
実行使用メモリ 54,628 KB
最終ジャッジ日時 2023-08-24 04:50:19
合計ジャッジ時間 5,961 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,396 KB
testcase_01 AC 43 ms
49,112 KB
testcase_02 AC 46 ms
49,260 KB
testcase_03 AC 44 ms
49,008 KB
testcase_04 AC 43 ms
48,996 KB
testcase_05 AC 42 ms
49,348 KB
testcase_06 AC 43 ms
49,140 KB
testcase_07 AC 43 ms
47,104 KB
testcase_08 AC 48 ms
48,984 KB
testcase_09 AC 49 ms
49,092 KB
testcase_10 AC 46 ms
49,000 KB
testcase_11 AC 47 ms
49,352 KB
testcase_12 AC 47 ms
49,000 KB
testcase_13 AC 77 ms
52,308 KB
testcase_14 AC 75 ms
51,248 KB
testcase_15 AC 76 ms
52,548 KB
testcase_16 AC 76 ms
52,364 KB
testcase_17 AC 71 ms
52,252 KB
testcase_18 AC 73 ms
51,540 KB
testcase_19 AC 75 ms
52,208 KB
testcase_20 AC 74 ms
51,332 KB
testcase_21 AC 75 ms
51,716 KB
testcase_22 AC 76 ms
51,824 KB
testcase_23 AC 76 ms
51,524 KB
testcase_24 AC 74 ms
52,192 KB
testcase_25 AC 76 ms
51,372 KB
testcase_26 AC 73 ms
51,580 KB
testcase_27 AC 77 ms
52,252 KB
testcase_28 AC 79 ms
52,372 KB
testcase_29 AC 76 ms
52,088 KB
testcase_30 AC 76 ms
52,288 KB
testcase_31 AC 77 ms
52,052 KB
testcase_32 AC 77 ms
52,032 KB
testcase_33 AC 72 ms
54,392 KB
testcase_34 AC 73 ms
53,380 KB
testcase_35 AC 73 ms
54,056 KB
testcase_36 AC 81 ms
52,344 KB
testcase_37 AC 73 ms
54,628 KB
testcase_38 AC 75 ms
54,176 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[] current = new int[1];
        current[0] = 1;
        int max = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            int[] next = new int[max + x + 1];
            for (int j = 0; j <= max; j++) {
                next[j + x] += current[j];
                next[j + x] %= MOD;
                next[Math.abs(j - x)] += current[j];
                next[Math.abs(j - x)] %= MOD;
            }
            max += x;
            current = next;
        }
        long ans = 0;
        for (int i = 1; i < current.length; i++) {
            ans += (long)i * current[i] % MOD;
            ans %= MOD;
        }
        System.out.println(ans);
    }
}
    
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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0