結果

問題 No.22 括弧の対応
ユーザー huffman56huffman56
提出日時 2022-04-17 11:42:11
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 69 ms / 5,000 ms
コード長 1,538 bytes
コンパイル時間 4,686 ms
コンパイル使用メモリ 108,012 KB
実行使用メモリ 23,864 KB
最終ジャッジ日時 2023-08-27 01:24:05
合計ジャッジ時間 7,042 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
21,796 KB
testcase_01 AC 57 ms
21,840 KB
testcase_02 AC 58 ms
21,848 KB
testcase_03 AC 69 ms
21,864 KB
testcase_04 AC 63 ms
21,848 KB
testcase_05 AC 61 ms
21,840 KB
testcase_06 AC 62 ms
19,884 KB
testcase_07 AC 63 ms
21,808 KB
testcase_08 AC 61 ms
21,940 KB
testcase_09 AC 62 ms
21,884 KB
testcase_10 AC 63 ms
21,808 KB
testcase_11 AC 60 ms
21,732 KB
testcase_12 AC 62 ms
21,940 KB
testcase_13 AC 64 ms
21,788 KB
testcase_14 AC 60 ms
21,804 KB
testcase_15 AC 64 ms
23,844 KB
testcase_16 AC 69 ms
23,864 KB
testcase_17 AC 58 ms
21,788 KB
testcase_18 AC 59 ms
23,836 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;

namespace yukicoder
{
    class Program
    {
        static void Main()
        {
            int[] nums = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToArray();
            int N = nums[0];
            int K = nums[1];
            string S = Console.ReadLine();
            int[] chk = new int[N];

            for (int i = 0; i < N; i++)
            {
                // 括弧の個数を管理する変数
                int kakko = 1;

                for (int j = i+1; j < N; j++)
                {
                    // すでに対応する数値が分かっている場合は処理をスキップ
                    if (chk[j] != 0)
                    {
                        break;
                    }

                    if (')'.Equals(S[j]))
                    {
                        kakko--;
                    }
                    else
                    {
                        kakko++;
                    }

                    if (kakko == 0)
                    {
                        chk[i] = j+1;
                        chk[j] = i+1;

                        break;
                    }
                }
            }

            Console.WriteLine(chk[K-1]);

        }
    }
}
0