結果
| 問題 | No.22 括弧の対応 |
| コンテスト | |
| ユーザー |
wowilson
|
| 提出日時 | 2016-10-08 15:59:39 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 5,000 ms |
| コード長 | 1,038 bytes |
| 記録 | |
| コンパイル時間 | 570 ms |
| コンパイル使用メモリ | 110,540 KB |
| 実行使用メモリ | 123,264 KB |
| 最終ジャッジ日時 | 2026-04-02 21:49:58 |
| 合計ジャッジ時間 | 1,459 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_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;
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]); //対応した( or )の番号を探す
var S = Console.ReadLine();
bool right = S[K - 1] == '(' ? true : false; //rightなら右方向に探索
char k = right ? '(' : ')'; //rightなら右方向に探索
int count = 0;
for (int i = K - 1; i < N;)
{
if (S[i] == k)
count++;
else
count--;
if (count == 0)
{
Console.WriteLine(i + 1);
return;
}
if (right)
{
i++;
}
else
{
i--;
}
}
}
}
}
wowilson