結果

問題 No.22 括弧の対応
ユーザー huffman56huffman56
提出日時 2022-04-17 11:16:29
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,521 bytes
コンパイル時間 3,725 ms
コンパイル使用メモリ 104,052 KB
実行使用メモリ 30,020 KB
最終ジャッジ日時 2023-08-27 01:13:56
合計ジャッジ時間 10,979 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
23,764 KB
testcase_01 AC 62 ms
23,876 KB
testcase_02 AC 62 ms
23,940 KB
testcase_03 AC 803 ms
28,000 KB
testcase_04 AC 234 ms
26,064 KB
testcase_05 AC 190 ms
26,036 KB
testcase_06 AC 359 ms
25,984 KB
testcase_07 WA -
testcase_08 AC 300 ms
23,836 KB
testcase_09 WA -
testcase_10 AC 508 ms
27,940 KB
testcase_11 AC 191 ms
27,928 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 712 ms
27,872 KB
testcase_16 AC 713 ms
28,072 KB
testcase_17 AC 63 ms
23,872 KB
testcase_18 AC 62 ms
23,936 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++)
            {
                // 対応する箇所が一通り分かったら処理をスキップする
                if (!chk.Contains(0))
                {
                    continue;
                }

                // 括弧の個数を管理する変数
                int kakko = 1;

                for (int j = i+1; j < N; j++)
                {

                    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