結果
問題 |
No.22 括弧の対応
|
ユーザー |
|
提出日時 | 2022-04-17 11:16:29 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,521 bytes |
コンパイル時間 | 3,425 ms |
コンパイル使用メモリ | 105,856 KB |
実行使用メモリ | 23,296 KB |
最終ジャッジ日時 | 2024-12-26 05:41:45 |
合計ジャッジ時間 | 9,383 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 WA * 5 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.IO; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Numerics; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using static System.Console; namespace yukicoder { class Program { static void Main() { int[] nums = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToArray(); int N = nums[0]; int K = nums[1]; string S = Console.ReadLine(); int[] chk = new int[N]; for (int i = 0; i < N; i++) { // 対応する箇所が一通り分かったら処理をスキップする if (!chk.Contains(0)) { continue; } // 括弧の個数を管理する変数 int kakko = 1; for (int j = i+1; j < N; j++) { if (')'.Equals(S[j])) { kakko--; } else { kakko++; } if (kakko == 0) { chk[i] = j+1; chk[j] = i+1; break; } } } Console.WriteLine(chk[K-1]); } } }