結果

問題 No.592 括弧の対応 (2)
ユーザー noriocnorioc
提出日時 2017-11-13 00:42:05
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 450 ms / 5,000 ms
コード長 818 bytes
コンパイル時間 584 ms
コンパイル使用メモリ 94,868 KB
実行使用メモリ 7,216 KB
最終ジャッジ日時 2023-09-03 16:53:42
合計ジャッジ時間 1,871 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 450 ms
7,216 KB
testcase_02 AC 59 ms
4,376 KB
testcase_03 AC 66 ms
6,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.map!(to!int).array; }

void calc(string s) {
    auto ans = new int[s.length];
    int[] stack;
    for (int i = 0; i < s.length; i++) {
        switch (s[i]) {
        case '(':
            stack ~= i;
            break;
        case ')':
            assert(stack.length > 0);
            int p = stack[$-1];
            stack = stack[0..$-1];
            ans[i] = p;
            ans[p] = i;
            break;
        default:
            break;
        }
    }

    foreach (p; ans)
        writeln(p + 1);
}

void main() {
    readint;
    auto s = readln.chomp;

    calc(s);
}
0