結果

問題 No.592 括弧の対応 (2)
ユーザー alpha_kai_NET
提出日時 2017-11-11 00:41:12
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 84 ms / 5,000 ms
コード長 844 bytes
コンパイル時間 977 ms
コンパイル使用メモリ 103,336 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-06-12 22:28:32
合計ジャッジ時間 1,781 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

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;
  size_t[size_t] map;
  int d;
  size_t[] c;
  c.length = N;


  foreach (i; 0..N) {
    if (S[i] == ')') d--;
    if (d in map) {
      c[i] = map[d] + 1;
      c[map[d]] = i + 1;
      map.remove(d);
    } else {
      map[d] = i;
    }
    if (S[i] == '(') d++;
  }

  foreach (a; c) {
    writeln(a);
  }
}
0