結果

問題 No.22 括弧の対応
ユーザー wowilsonwowilson
提出日時 2016-10-08 02:44:32
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 140 ms / 5,000 ms
コード長 1,412 bytes
コンパイル時間 2,699 ms
コンパイル使用メモリ 104,944 KB
実行使用メモリ 25,676 KB
最終ジャッジ日時 2023-09-27 13:09:11
合計ジャッジ時間 4,075 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
19,624 KB
testcase_01 AC 53 ms
21,660 KB
testcase_02 AC 54 ms
21,576 KB
testcase_03 AC 79 ms
21,768 KB
testcase_04 AC 62 ms
23,724 KB
testcase_05 AC 60 ms
21,532 KB
testcase_06 AC 84 ms
23,640 KB
testcase_07 AC 61 ms
21,596 KB
testcase_08 AC 56 ms
21,724 KB
testcase_09 AC 84 ms
25,676 KB
testcase_10 AC 58 ms
21,644 KB
testcase_11 AC 62 ms
21,560 KB
testcase_12 AC 73 ms
21,596 KB
testcase_13 AC 140 ms
21,596 KB
testcase_14 AC 57 ms
23,856 KB
testcase_15 AC 72 ms
21,760 KB
testcase_16 AC 85 ms
23,732 KB
testcase_17 AC 53 ms
21,600 KB
testcase_18 AC 56 ms
23,884 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 Yukicoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ');

            int N = int.Parse(line[0]);
            int K = int.Parse(line[1]) - 1;

            List<int> list = new List<int>();
            var kakko = Console.ReadLine()
                .Select(
                x => x == '(' ? 0 : 1
                );

            list.AddRange(kakko);
            while (true)
            {
                int lastKakko = 0;
                for (int i = 0; i < N; i++)
                {
                    if(list[i] == 0)
                    {
                        lastKakko = i;
                        continue;
                    }

                    if(list[i] == 1)
                    {
                        list[lastKakko] = -1;
                        list[i] = -1;

                        if(lastKakko == K)
                        {
                            Console.WriteLine(i + 1);
                            return;
                        }else if(i == K)
                        {
                            Console.WriteLine(lastKakko + 1);
                            return;
                        }
                        break;
                    }
                }
            }
            
        }

    }
}
0