結果

問題 No.22 括弧の対応
ユーザー kmtrc130
提出日時 2017-04-03 16:26:47
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 857 bytes
コンパイル時間 1,026 ms
コンパイル使用メモリ 113,156 KB
実行使用メモリ 27,272 KB
最終ジャッジ日時 2024-07-08 03:22:39
合計ジャッジ時間 2,291 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 WA * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

class Program
{
    static void Main(string[] args)
    {
        int[] NK = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        char[] S = Console.ReadLine().ToArray();

        int kakko = 0;
        int idx = 0;

        if ('('.Equals(S[NK[1] - 1]))
        {
            for (idx = NK[1]; idx < S.Length; idx++)
            {
                if (kakko < 0) break;
                if ('('.Equals(S[idx])) kakko++;
                if (')'.Equals(S[idx])) kakko--;
            }
        }
        else
        {
            for (idx = NK[1] - 2; 0 < idx; idx--)
            {
                if (kakko < 0) break;
                if (')'.Equals(S[idx])) kakko++;
                if ('('.Equals(S[idx])) kakko--;
            }
            idx =- 1;
        }
        Console.WriteLine(idx);
    }
}
0