結果
| 問題 |
No.592 括弧の対応 (2)
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2017-11-13 00:42:05 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 457 ms / 5,000 ms |
| コード長 | 818 bytes |
| コンパイル時間 | 691 ms |
| コンパイル使用メモリ | 103,912 KB |
| 実行使用メモリ | 6,940 KB |
| 最終ジャッジ日時 | 2024-06-12 22:31:25 |
| 合計ジャッジ時間 | 1,829 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 |
ソースコード
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);
}
norioc