結果

問題 No.592 括弧の対応 (2)
ユーザー alpha_kai_NETalpha_kai_NET
提出日時 2017-11-10 22:42:59
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 821 bytes
コンパイル時間 876 ms
コンパイル使用メモリ 90,160 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-09-03 16:47:35
合計ジャッジ時間 7,474 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,756 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.functional,
       std.algorithm,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

size_t bracketState(string s) {
  size_t bracketState = 1;
  size_t idx;
  while (bracketState != 0 && idx < s.length) {
    char ch = s[idx];
    if (ch == '(') { bracketState++; }
    if (ch == ')') { bracketState--; }
    idx++;
  }
  return idx;
}

struct Pair {
  size_t b, e;
}

void main() {
  int N = readln.chomp.to!(int);
  string S = readln.chomp;
  Pair[] ps;
  size_t bi, ei;

  foreach (idx, s; S) {
    if (s == '(') {
      ps ~= Pair(idx, idx + S[idx+1..$].bracketState);
    }
  }

  size_t[] ans;
  ans.length = N;

  foreach (p; ps) {
    ans[p.b] = p.e;
    ans[p.e] = p.b;
  }

  foreach (a; ans) {
    writeln(a + 1);
  }
}
0