結果

問題 No.22 括弧の対応
ユーザー HimatsubushinHimatsubushin
提出日時 2021-01-13 09:42:29
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 66 ms / 5,000 ms
コード長 1,108 bytes
コンパイル時間 3,250 ms
コンパイル使用メモリ 105,500 KB
実行使用メモリ 23,800 KB
最終ジャッジ日時 2023-08-14 06:40:40
合計ジャッジ時間 5,421 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
21,668 KB
testcase_01 AC 62 ms
21,676 KB
testcase_02 AC 61 ms
21,688 KB
testcase_03 AC 63 ms
21,612 KB
testcase_04 AC 63 ms
23,632 KB
testcase_05 AC 64 ms
21,556 KB
testcase_06 AC 63 ms
23,592 KB
testcase_07 AC 64 ms
21,636 KB
testcase_08 AC 64 ms
21,648 KB
testcase_09 AC 64 ms
23,700 KB
testcase_10 AC 63 ms
21,556 KB
testcase_11 AC 64 ms
23,800 KB
testcase_12 AC 63 ms
23,652 KB
testcase_13 AC 64 ms
23,720 KB
testcase_14 AC 63 ms
21,628 KB
testcase_15 AC 66 ms
23,620 KB
testcase_16 AC 63 ms
21,680 KB
testcase_17 AC 62 ms
21,624 KB
testcase_18 AC 62 ms
21,628 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.Collections.Generic;
using System.Linq;

namespace No_22
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]) - 1;
            string text = Console.ReadLine();
            int[] pair = new int[text.Length];
            int start = 1;
            Stack<int> num = new Stack<int>();

            foreach (var moji in text.Select((c, i) => new {c, i}))
            {
                if (moji.c == '(')
                {
                    num.Push(start);
                    pair[moji.i] = start;
                    start++;
                }
                else
                {
                    pair[moji.i] = num.Pop();
                }
            }

            foreach (var data in pair.Select((n, i) => new {n, i}))
            {
                if (data.i != k && data.n == pair[k])
                {
                    Console.WriteLine(data.i + 1);
                }
            }
        }
    }
}
0