結果

問題 No.22 括弧の対応
ユーザー suzusuzu
提出日時 2023-04-21 12:01:08
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,189 bytes
コンパイル時間 905 ms
コンパイル使用メモリ 112,148 KB
実行使用メモリ 29,112 KB
最終ジャッジ日時 2024-04-24 01:33:22
合計ジャッジ時間 2,405 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,220 KB
testcase_01 AC 28 ms
25,340 KB
testcase_02 AC 29 ms
25,344 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 29 ms
25,368 KB
testcase_08 WA -
testcase_09 AC 30 ms
25,268 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 29 ms
25,116 KB
testcase_18 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;

namespace yukicoder
{
    class Program
    {

        static void Main(string[] args)
        {
            var line1 = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToArray();
            string line2 = Console.ReadLine();
            
            int n = line1[0];
            int k = line1[1];
            string s = line2;
            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;
                    }
                }
            }
            Console.WriteLine(chk[k - 1]);
            
            
                
            
        }
    }
}
0