結果
| 問題 | 
                            No.22 括弧の対応
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-04-25 21:53:04 | 
| 言語 | C#(csc)  (csc 3.9.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 226 ms / 5,000 ms | 
| コード長 | 1,857 bytes | 
| コンパイル時間 | 962 ms | 
| コンパイル使用メモリ | 108,672 KB | 
| 実行使用メモリ | 43,232 KB | 
| 最終ジャッジ日時 | 2024-07-20 07:42:23 | 
| 合計ジャッジ時間 | 3,402 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| 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;
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;
        }
    }
}