結果

問題 No.2591 安上がりな括弧列
ユーザー 👑 kakel-sankakel-san
提出日時 2023-12-20 22:25:49
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 955 bytes
コンパイル時間 15,190 ms
コンパイル使用メモリ 158,632 KB
実行使用メモリ 212,428 KB
最終ジャッジ日時 2023-12-20 22:26:10
合計ジャッジ時間 20,231 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
32,676 KB
testcase_01 AC 79 ms
32,804 KB
testcase_02 AC 79 ms
32,804 KB
testcase_03 AC 79 ms
32,932 KB
testcase_04 AC 79 ms
32,804 KB
testcase_05 AC 81 ms
32,932 KB
testcase_06 AC 81 ms
32,804 KB
testcase_07 AC 79 ms
32,804 KB
testcase_08 AC 79 ms
32,804 KB
testcase_09 AC 84 ms
33,316 KB
testcase_10 AC 79 ms
32,932 KB
testcase_11 AC 149 ms
65,444 KB
testcase_12 AC 144 ms
65,444 KB
testcase_13 AC 146 ms
65,444 KB
testcase_14 AC 144 ms
65,444 KB
testcase_15 AC 152 ms
65,444 KB
testcase_16 AC 145 ms
64,804 KB
testcase_17 AC 98 ms
41,380 KB
testcase_18 AC 112 ms
48,420 KB
testcase_19 AC 105 ms
44,708 KB
testcase_20 AC 144 ms
65,316 KB
testcase_21 AC 148 ms
65,444 KB
testcase_22 AC 157 ms
212,428 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (104 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN * 2;
        var s = ReadLine();
        var a = NList;
        var dp = new long[n + 1][];
        for (var i = 0; i < dp.Length; ++i) dp[i] = Enumerable.Repeat(long.MaxValue / 2, n + 1).ToArray();
        dp[0][0] = 0;
        for (var i = 0; i < n; ++i) for (var j = 0; j < dp[i].Length; ++j)
        {
            if (j - 1 >= 0) dp[i + 1][j - 1] = Math.Min(dp[i + 1][j - 1], dp[i][j] + (s[i] == '(' ? a[i] : 0));
            if (j + 1 < dp[i].Length) dp[i + 1][j + 1] = Math.Min(dp[i + 1][j + 1], dp[i][j] + (s[i] == ')' ? a[i] : 0));
        }
        WriteLine(dp[n][0]);
    }
}
0