結果

問題 No.22 括弧の対応
ユーザー tanukidontanukidon
提出日時 2018-04-25 01:48:49
言語 Ruby
(3.3.0)
結果
AC  
実行時間 4,725 ms / 5,000 ms
コード長 550 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 16,896 KB
最終ジャッジ日時 2023-12-20 21:10:35
合計ジャッジ時間 17,239 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
16,128 KB
testcase_01 AC 85 ms
16,128 KB
testcase_02 AC 84 ms
16,128 KB
testcase_03 AC 1,367 ms
16,896 KB
testcase_04 AC 347 ms
16,512 KB
testcase_05 AC 259 ms
16,512 KB
testcase_06 AC 2,006 ms
16,640 KB
testcase_07 AC 371 ms
16,768 KB
testcase_08 AC 121 ms
16,512 KB
testcase_09 AC 1,426 ms
16,512 KB
testcase_10 AC 165 ms
16,640 KB
testcase_11 AC 285 ms
16,512 KB
testcase_12 AC 1,278 ms
16,512 KB
testcase_13 AC 4,725 ms
16,896 KB
testcase_14 AC 111 ms
16,256 KB
testcase_15 AC 1,173 ms
16,768 KB
testcase_16 AC 1,697 ms
16,896 KB
testcase_17 AC 83 ms
16,128 KB
testcase_18 AC 83 ms
16,128 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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] == ""
      t = 0
      t = j
      i = t
      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
   j = 1 if j == n
end
0