結果

問題 No.22 括弧の対応
ユーザー bluemeganebluemegane
提出日時 2018-09-22 10:20:33
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 55 ms / 5,000 ms
コード長 628 bytes
コンパイル時間 2,288 ms
コンパイル使用メモリ 102,208 KB
実行使用メモリ 22,780 KB
最終ジャッジ日時 2023-09-27 13:30:48
合計ジャッジ時間 4,125 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
20,736 KB
testcase_01 AC 51 ms
20,860 KB
testcase_02 AC 52 ms
20,856 KB
testcase_03 AC 54 ms
20,684 KB
testcase_04 AC 54 ms
20,680 KB
testcase_05 AC 52 ms
20,864 KB
testcase_06 AC 52 ms
18,812 KB
testcase_07 AC 54 ms
20,736 KB
testcase_08 AC 55 ms
20,832 KB
testcase_09 AC 53 ms
20,696 KB
testcase_10 AC 53 ms
22,708 KB
testcase_11 AC 53 ms
18,636 KB
testcase_12 AC 53 ms
20,772 KB
testcase_13 AC 53 ms
22,712 KB
testcase_14 AC 53 ms
22,780 KB
testcase_15 AC 52 ms
20,872 KB
testcase_16 AC 54 ms
22,716 KB
testcase_17 AC 52 ms
20,768 KB
testcase_18 AC 53 ms
20,608 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        var st = new Stack<int>();
        var s = Console.ReadLine().Trim();
        for (int i = 0; i < s.Length; i++)
            if (s[i] == '(') st.Push(i + 1);
            else
            {
                var w = st.Pop();
                if (w == k) { Console.WriteLine(i + 1); break; }
                else if (i + 1 == k) { Console.WriteLine(w); break; }
            }
    }
}
0