結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-08-20 23:44:49 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 5,000 ms |
| コード長 | 713 bytes |
| コンパイル時間 | 1,421 ms |
| コンパイル使用メモリ | 106,880 KB |
| 実行使用メモリ | 19,072 KB |
| 最終ジャッジ日時 | 2024-07-20 07:15:37 |
| 合計ジャッジ時間 | 2,713 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Linq;
public class Test
{
public static void Main()
{
int[] NK = Console.ReadLine().Split().Select(i => int.Parse(i))
.ToArray();
int N = NK[0];
int K = NK[1] - 1;
string S = Console.ReadLine();
if (S[K] == '(')
{
int attr = 1;
for (int i = K + 1; i < S.Length; i++)
{
if (S[i] == '(')
{
attr++;
}
else
{
if (--attr == 0)
{
Console.WriteLine(i + 1);
return;
}
}
}
}
else
{
int attr = -1;
for (int i = K - 1; i >= 0; i--)
{
if (S[i] == ')')
{
attr--;
}
else
{
if (++attr == 0)
{
Console.WriteLine(i + 1);
return;
}
}
}
}
}
}