結果

問題 No.2031 Colored Brackets
ユーザー 👑 kakel-sankakel-san
提出日時 2022-08-05 23:21:31
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 1,254 bytes
コンパイル時間 1,594 ms
コンパイル使用メモリ 65,724 KB
実行使用メモリ 47,776 KB
最終ジャッジ日時 2023-10-14 01:13:20
合計ジャッジ時間 6,553 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
22,836 KB
testcase_01 AC 55 ms
20,636 KB
testcase_02 AC 57 ms
22,752 KB
testcase_03 AC 56 ms
22,748 KB
testcase_04 AC 85 ms
28,940 KB
testcase_05 AC 68 ms
26,840 KB
testcase_06 AC 73 ms
24,800 KB
testcase_07 AC 55 ms
20,632 KB
testcase_08 AC 120 ms
47,596 KB
testcase_09 AC 135 ms
42,484 KB
testcase_10 AC 154 ms
42,084 KB
testcase_11 AC 132 ms
42,868 KB
testcase_12 AC 162 ms
39,428 KB
testcase_13 AC 107 ms
36,428 KB
testcase_14 AC 165 ms
39,284 KB
testcase_15 AC 165 ms
39,212 KB
testcase_16 AC 164 ms
41,176 KB
testcase_17 AC 160 ms
41,128 KB
testcase_18 AC 170 ms
39,320 KB
testcase_19 AC 150 ms
40,860 KB
testcase_20 AC 121 ms
47,776 KB
testcase_21 AC 121 ms
45,216 KB
testcase_22 AC 129 ms
44,088 KB
testcase_23 AC 164 ms
41,680 KB
testcase_24 AC 55 ms
20,688 KB
testcase_25 AC 56 ms
20,740 KB
testcase_26 AC 55 ms
20,704 KB
testcase_27 AC 55 ms
20,632 KB
testcase_28 AC 55 ms
20,820 KB
testcase_29 AC 57 ms
20,720 KB
testcase_30 AC 55 ms
20,636 KB
testcase_31 AC 56 ms
20,700 KB
testcase_32 AC 55 ms
20,740 KB
testcase_33 AC 57 ms
22,612 KB
権限があれば一括ダウンロードができます

ソースコード

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();
    static void Main()
    {
        var n = NN;
        var s = ReadLine();
        WriteLine(Brac(n, s));
    }
    static long Brac(int n, string s)
    {
        var dp = new int[n];
        dp[0] = 1;
        for (var i = 1; i < n; ++i)
        {
            if (s[i] == '(') dp[i] = dp[i - 1] + 1;
            else dp[i] = dp[i - 1] - 1;
        }
        var br = new long[s.Length / 2 + 1];
        br[0] = 1;
        for (var i = 0; i < s.Length; ++i)
        {
            var next = (long[]) br.Clone();
            if (s[i] == '(')
            {
                for (var j = 0; j + 1 < br.Length; ++j) next[j + 1] = (next[j + 1] + br[j]) % mod;
            }
            else
            {
                for (var j = 1; j < br.Length; ++j) next[j - 1] = (next[j - 1] + br[j]) % mod;
            }
            for (var j = dp[i] + 1; j < next.Length; ++j) next[j] = 0;
            br = next;
        }
        return br[0];
    }
    static int mod = 998_244_353;
}
0