結果
| 問題 |
No.22 括弧の対応
|
| ユーザー |
nishima
|
| 提出日時 | 2015-10-12 01:22:50 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 422 bytes |
| コンパイル時間 | 46 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 12,800 KB |
| 最終ジャッジ日時 | 2024-07-21 07:07:20 |
| 合計ジャッジ時間 | 2,805 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 5 |
コンパイルメッセージ
Syntax OK
ソースコード
d1 = $stdin.gets.chomp.split(/ /).map(&:to_i)
d2 = $stdin.gets.chomp.split(//).map{ |e|
if e == '(' then 1
else -1
end
}
n = d1[ 0 ]
k = d1[ 1 ]
ans = 0
if d2[ k - 1 ] == 1 # '('
sum = d2[ k - 1 ]
k.upto( n - 1 ){ |i|
sum += d2[ i ]
if sum == 0
ans = i + 1
break
end
}
else # ')'
sum = d2[ k - 1 ]
(k-2).downto( 0 ){ |i|
sum += d2[ i ]
if sum == 0
ans = i + 1
end
}
end
puts ans
nishima