結果
| 問題 | No.22 括弧の対応 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-02-27 14:51:01 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 17 ms / 5,000 ms |
| コード長 | 751 bytes |
| 記録 | |
| コンパイル時間 | 513 ms |
| コンパイル使用メモリ | 104,832 KB |
| 実行使用メモリ | 123,392 KB |
| 最終ジャッジ日時 | 2026-04-02 21:51:33 |
| 合計ジャッジ時間 | 1,337 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
| 純コード判定待ち |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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();
}
}