結果

問題 No.22 括弧の対応
ユーザー swdamdrswdamdr
提出日時 2017-02-27 14:51:01
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 55 ms / 5,000 ms
コード長 751 bytes
コンパイル時間 2,383 ms
コンパイル使用メモリ 108,548 KB
実行使用メモリ 22,888 KB
最終ジャッジ日時 2023-09-27 13:12:07
合計ジャッジ時間 3,684 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
20,852 KB
testcase_01 AC 52 ms
20,808 KB
testcase_02 AC 51 ms
20,788 KB
testcase_03 AC 53 ms
20,756 KB
testcase_04 AC 53 ms
20,872 KB
testcase_05 AC 52 ms
20,896 KB
testcase_06 AC 54 ms
20,816 KB
testcase_07 AC 54 ms
20,772 KB
testcase_08 AC 55 ms
20,764 KB
testcase_09 AC 54 ms
22,852 KB
testcase_10 AC 54 ms
22,884 KB
testcase_11 AC 54 ms
22,800 KB
testcase_12 AC 54 ms
20,748 KB
testcase_13 AC 55 ms
20,884 KB
testcase_14 AC 54 ms
20,676 KB
testcase_15 AC 55 ms
20,728 KB
testcase_16 AC 55 ms
22,888 KB
testcase_17 AC 52 ms
20,652 KB
testcase_18 AC 53 ms
18,832 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.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        string[] x = Console.ReadLine().Split();
        string s = Console.ReadLine();

        int n = int.Parse(x[0]);
        int k = int.Parse(x[1]);
        List<int> lst = new List<int>();
        int[] ary = new int[n];

        for (int i = 0; i < n; i++)
        {
            if (s[i] == '(')
            {
                lst.Add(i);
            }
            else
            {
                ary[lst[lst.Count - 1]] = i;
                ary[i] = lst[lst.Count - 1];
                lst.RemoveAt(lst.Count - 1);
            }
        }

        Console.WriteLine(ary[k - 1] + 1);
        Console.Read();
    }
}
0