結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-02-27 14:51:01 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 5,000 ms |
| コード長 | 751 bytes |
| コンパイル時間 | 750 ms |
| コンパイル使用メモリ | 104,448 KB |
| 実行使用メモリ | 17,920 KB |
| 最終ジャッジ日時 | 2024-07-20 07:20:02 |
| 合計ジャッジ時間 | 1,763 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
string[] x = Console.ReadLine().Split();
string s = Console.ReadLine();
int n = int.Parse(x[0]);
int k = int.Parse(x[1]);
List<int> lst = new List<int>();
int[] ary = new int[n];
for (int i = 0; i < n; i++)
{
if (s[i] == '(')
{
lst.Add(i);
}
else
{
ary[lst[lst.Count - 1]] = i;
ary[i] = lst[lst.Count - 1];
lst.RemoveAt(lst.Count - 1);
}
}
Console.WriteLine(ary[k - 1] + 1);
Console.Read();
}
}