結果

問題 No.1645 AB's abs
ユーザー masayamatumasayamatu
提出日時 2021-09-04 12:01:19
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 1,462 bytes
コンパイル時間 14,757 ms
コンパイル使用メモリ 145,360 KB
実行使用メモリ 166,260 KB
最終ジャッジ日時 2023-08-22 19:06:39
合計ジャッジ時間 14,529 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
29,212 KB
testcase_01 AC 53 ms
31,152 KB
testcase_02 AC 58 ms
30,668 KB
testcase_03 AC 55 ms
28,896 KB
testcase_04 AC 54 ms
29,008 KB
testcase_05 AC 54 ms
29,224 KB
testcase_06 AC 54 ms
29,248 KB
testcase_07 AC 55 ms
29,044 KB
testcase_08 AC 59 ms
31,352 KB
testcase_09 AC 61 ms
31,668 KB
testcase_10 AC 59 ms
31,044 KB
testcase_11 AC 60 ms
31,636 KB
testcase_12 AC 60 ms
31,416 KB
testcase_13 AC 85 ms
43,024 KB
testcase_14 AC 77 ms
38,804 KB
testcase_15 AC 86 ms
41,088 KB
testcase_16 AC 84 ms
39,056 KB
testcase_17 AC 83 ms
38,724 KB
testcase_18 AC 82 ms
41,080 KB
testcase_19 AC 84 ms
41,320 KB
testcase_20 AC 79 ms
40,892 KB
testcase_21 AC 82 ms
41,016 KB
testcase_22 AC 85 ms
41,512 KB
testcase_23 AC 84 ms
41,520 KB
testcase_24 AC 86 ms
40,936 KB
testcase_25 AC 85 ms
40,944 KB
testcase_26 AC 83 ms
41,180 KB
testcase_27 AC 85 ms
39,192 KB
testcase_28 AC 84 ms
41,496 KB
testcase_29 AC 85 ms
41,228 KB
testcase_30 AC 87 ms
41,272 KB
testcase_31 AC 86 ms
38,372 KB
testcase_32 AC 87 ms
41,156 KB
testcase_33 AC 98 ms
39,732 KB
testcase_34 AC 98 ms
39,576 KB
testcase_35 AC 96 ms
39,496 KB
testcase_36 AC 96 ms
39,432 KB
testcase_37 AC 97 ms
39,624 KB
testcase_38 AC 56 ms
166,260 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  Determining projects to restore...
  Restored /home/judge/data/code/main.csproj (in 138 ms).
.NET 向け Microsoft (R) Build Engine バージョン 17.0.0-preview-21470-01+cb055d28f
Copyright (C) Microsoft Corporation.All rights reserved.

  プレビュー版の .NET を使用しています。https://aka.ms/dotnet-core-preview をご覧ください
  main -> /home/judge/data/code/bin/Release/net6.0/main.dll
  main -> /home/judge/data/code/bin/Release/net6.0/publish/

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace yukicoder
{
    class Program
    {
        const int intMax = 1000000000;
        const long longMax = 2000000000000000000;
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var dp = new Dictionary<int, long>();
            long mod = 998244353;
            dp[0] = 1;
            for(int i = 0; i < N; i++)
            {
                var temp = new Dictionary<int, long>();
                foreach(var d in dp)
                {
                    if(!temp.ContainsKey(d.Key + A[i]))
                    {
                        temp.Add(d.Key + A[i],0);
                    }
                    if(!temp.ContainsKey(d.Key - A[i]))
                    {
                        temp.Add(d.Key - A[i],0);
                    }                    
                    temp[d.Key + A[i]] = (temp[d.Key + A[i]] + d.Value) % mod;
                    temp[d.Key - A[i]] = (temp[d.Key - A[i]] + d.Value) % mod;             
                }
                dp = temp;
            }
            long ans = 0;
            foreach(var d in dp)
            {
                ans = (ans + (Math.Abs(d.Key) * d.Value) % mod ) % mod;
            }
            Console.WriteLine(ans);
        }
    }
}
0