結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
wowilson
|
| 提出日時 | 2016-10-08 02:44:32 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 125 ms / 5,000 ms |
| コード長 | 1,412 bytes |
| コンパイル時間 | 963 ms |
| コンパイル使用メモリ | 107,648 KB |
| 実行使用メモリ | 19,200 KB |
| 最終ジャッジ日時 | 2024-07-20 07:17:04 |
| 合計ジャッジ時間 | 2,599 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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.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;
}
}
}
}
}
}
wowilson