結果
問題 | No.22 括弧の対応 |
ユーザー | PoronPa |
提出日時 | 2019-04-25 21:53:04 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 324 ms / 5,000 ms |
コード長 | 1,857 bytes |
コンパイル時間 | 2,313 ms |
コンパイル使用メモリ | 108,648 KB |
実行使用メモリ | 47,312 KB |
最終ジャッジ日時 | 2023-09-27 13:37:34 |
合計ジャッジ時間 | 6,317 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 81 ms
24,288 KB |
testcase_01 | AC | 80 ms
22,216 KB |
testcase_02 | AC | 80 ms
20,288 KB |
testcase_03 | AC | 324 ms
44,304 KB |
testcase_04 | AC | 125 ms
47,312 KB |
testcase_05 | AC | 114 ms
42,452 KB |
testcase_06 | AC | 178 ms
46,520 KB |
testcase_07 | AC | 228 ms
46,120 KB |
testcase_08 | AC | 152 ms
46,424 KB |
testcase_09 | AC | 135 ms
46,228 KB |
testcase_10 | AC | 211 ms
46,220 KB |
testcase_11 | AC | 112 ms
39,780 KB |
testcase_12 | AC | 155 ms
44,432 KB |
testcase_13 | AC | 225 ms
46,828 KB |
testcase_14 | AC | 84 ms
24,408 KB |
testcase_15 | AC | 282 ms
46,512 KB |
testcase_16 | AC | 288 ms
44,284 KB |
testcase_17 | AC | 81 ms
24,308 KB |
testcase_18 | AC | 81 ms
22,152 KB |
コンパイルメッセージ
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; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); string text= Console.ReadLine(); Palen Ans = new Palen(int.Parse(str[0]), text); Ans.calc(); Console.WriteLine(Ans.Ans(int.Parse(str[1])).ToString()); Console.ReadLine(); } class Palen { string Str = String.Empty; int[,] AnsPair; int PairCount=0; int[] StrIndex; public Palen(int StrLength,string ininput) { Str = ininput; AnsPair = new int[2,StrLength / 2]; StrIndex = new int[StrLength]; StrIndex = StrIndex.Select((x, index) => x = index+1).ToArray(); } public void calc() { while (Str!="") { int IndexPair = Str.IndexOf("()"); AnsPair[0, PairCount] = StrIndex[IndexPair]; AnsPair[1, PairCount] = StrIndex[IndexPair + 1]; Str = Str.Substring(0, IndexPair) + Str.Substring(IndexPair + 2);//Str.Length-1 int[] NewStrIndex = new int[StrIndex.Length - 2]; for (int Loop1 = 0; Loop1 < NewStrIndex.Length; Loop1++) { NewStrIndex[Loop1] = Loop1 < IndexPair ? StrIndex[Loop1] : StrIndex[Loop1 + 2]; } StrIndex = NewStrIndex; PairCount++; } } public int Ans(int inIndex) { for (int Loop1 = 0; Loop1 < AnsPair.GetLength(1); Loop1++) { if (inIndex == AnsPair[0,Loop1]) { return AnsPair[1, Loop1]; } if (inIndex == AnsPair[1, Loop1]) { return AnsPair[0, Loop1]; } } return -1; } } }