結果

問題 No.22 括弧の対応
ユーザー suzu
提出日時 2023-04-21 12:03:39
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 1,220 bytes
コンパイル時間 2,342 ms
コンパイル使用メモリ 112,780 KB
実行使用メモリ 27,396 KB
最終ジャッジ日時 2024-11-06 08:13:42
合計ジャッジ時間 3,995 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
                        break;
                    }
                }
            }
            Console.WriteLine(chk[k - 1]);
            
            
                
            
        }
    }
}
0