結果

問題 No.22 括弧の対応
ユーザー tanukidontanukidon
提出日時 2018-04-25 01:33:36
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 527 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 11,240 KB
実行使用メモリ 19,920 KB
最終ジャッジ日時 2023-09-10 05:14:57
合計ジャッジ時間 13,473 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n,m = gets.split.map(&:to_i)
s = gets.chomp.split("")
i = 0
j = 1
loop do
  if s[i] == "(" && s[j] == ")"
    s[i] = ""
    s[j] = ""
    if i+1 == m || j+1 == m
      if i+1 == m
        p j+1
      else
        p i+1
      end
      break
    end
    i = 0
    j = 1
  elsif s[i] == "(" && s[j] == "("
    if s[j-1] == ""
      i = j
      j += 1
    else
      i += 1
      j += 1
    end
  elsif s[i] == "(" && s[j] == ""
    j += 1
  elsif s[i] == ""
    i += 1
    j += 1
  end
  i = 0 if i == n-1
  j = 1 if j == n-1
end
0