結果

問題 No.592 括弧の対応 (2)
ユーザー mbanmban
提出日時 2017-12-01 18:48:50
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 93 ms / 5,000 ms
コード長 2,077 bytes
コンパイル時間 4,690 ms
コンパイル使用メモリ 103,960 KB
実行使用メモリ 34,068 KB
最終ジャッジ日時 2023-08-18 16:14:32
合計ジャッジ時間 4,582 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
20,708 KB
testcase_01 AC 93 ms
34,068 KB
testcase_02 AC 93 ms
31,976 KB
testcase_03 AC 90 ms
31,972 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Scanner
{
    private readonly char Separator = ' ';
    private int Index = 0;
    private string[] Line = new string[0];
    public string Next()
    {
        if (Index >= Line.Length)
        {
            Line = Console.ReadLine().Split(Separator);
            Index = 0;
        }
        var ret = Line[Index];
        Index++;
        return ret;
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public string[] StringArray()
    {
        Line = Console.ReadLine().Split(Separator);
        Index = Line.Length;
        return Line;
    }

    public int[] IntArray()
    {
        var l = StringArray();
        var res = new int[l.Length];
        for (int i = 0; i < l.Length; i++)
        {
            res[i] = int.Parse(l[i]);
        }
        return res;
    }

    public long[] LongArray()
    {
        var l = StringArray();
        var res = new long[l.Length];
        for (int i = 0; i < l.Length; i++)
        {
            res[i] = long.Parse(l[i]);
        }
        return res;
    }
}

class Program
{
    private int N;
    private string S;
    private void Scan()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        S = sc.Next();
    }

    public void Solve()
    {
        Scan();
        var ans = new int[N];
        var map = new int[N];
        for (int i = 0; i < N; i++)
        {
            map[i] = -1;
        }
        int cnt = 0;
        for (int i = 0; i < N; i++)
        {
            if(S[i]=='(')
            {
                map[cnt] = i;
                cnt++;
            }
            else
            {
                cnt--;
                ans[map[cnt]] = i + 1;
                ans[i] = map[cnt] + 1;
            }
        }
        Console.WriteLine(string.Join("\n", ans));
    }

    static void Main(string[] args)
    {
        new Program().Solve();
    }
}
0