結果

問題 No.1645 AB's abs
ユーザー merlinmerlin
提出日時 2021-08-13 21:42:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 945 bytes
コンパイル時間 2,158 ms
コンパイル使用メモリ 78,012 KB
実行使用メモリ 64,580 KB
最終ジャッジ日時 2024-04-14 17:20:22
合計ジャッジ時間 8,074 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
49,720 KB
testcase_01 AC 52 ms
50,288 KB
testcase_02 AC 95 ms
56,624 KB
testcase_03 AC 51 ms
50,236 KB
testcase_04 AC 53 ms
49,948 KB
testcase_05 AC 60 ms
50,384 KB
testcase_06 AC 84 ms
51,440 KB
testcase_07 AC 56 ms
50,272 KB
testcase_08 AC 96 ms
56,448 KB
testcase_09 AC 97 ms
56,596 KB
testcase_10 AC 96 ms
56,768 KB
testcase_11 AC 97 ms
56,464 KB
testcase_12 AC 96 ms
56,688 KB
testcase_13 AC 136 ms
64,156 KB
testcase_14 AC 135 ms
63,968 KB
testcase_15 AC 139 ms
64,144 KB
testcase_16 AC 132 ms
64,020 KB
testcase_17 AC 134 ms
64,048 KB
testcase_18 AC 135 ms
63,756 KB
testcase_19 AC 134 ms
63,928 KB
testcase_20 AC 126 ms
64,024 KB
testcase_21 AC 132 ms
63,980 KB
testcase_22 AC 141 ms
64,060 KB
testcase_23 AC 136 ms
64,388 KB
testcase_24 AC 139 ms
64,248 KB
testcase_25 AC 142 ms
64,560 KB
testcase_26 AC 141 ms
64,176 KB
testcase_27 AC 140 ms
64,268 KB
testcase_28 AC 138 ms
64,476 KB
testcase_29 AC 143 ms
64,500 KB
testcase_30 AC 139 ms
64,512 KB
testcase_31 AC 143 ms
64,444 KB
testcase_32 AC 141 ms
64,580 KB
testcase_33 AC 137 ms
64,252 KB
testcase_34 AC 136 ms
64,548 KB
testcase_35 AC 132 ms
64,500 KB
testcase_36 AC 136 ms
64,524 KB
testcase_37 AC 133 ms
64,192 KB
testcase_38 AC 137 ms
64,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        int n=Integer.parseInt(bu.readLine());
        int a[]=new int[n],i,j,N=10000;
        String s[]=bu.readLine().split(" ");
        for(i=0;i<n;i++) a[i]=Integer.parseInt(s[i]);

        long dp[][]=new long[n][2*N+1],M=998244353;
        dp[0][a[0]+N]=1;
        dp[0][N-a[0]]=1;
        for(i=1;i<n;i++)
        for(j=0;j<=2*N;j++)
        {
            if(j-a[i]>=0) dp[i][j-a[i]]=(dp[i][j-a[i]]+dp[i-1][j])%M;
            if(j+a[i]<=2*N) dp[i][j+a[i]]=(dp[i][j+a[i]]+dp[i-1][j])%M;
        }

        long ans=0;
        for(i=0;i<=N;i++)
        ans=(ans+dp[n-1][i]*(N-i)%M)%M;
        for(i=N+1;i<=2*N;i++)
        ans=(ans+dp[n-1][i]*(i-N)%M)%M;
        System.out.println(ans);
    }
}
0