fork(1) download
  1. class String
  2. def rgsub(pattern, replace)
  3. s = gsub(pattern, replace)
  4. self == s ? s : s.rgsub(pattern, replace)
  5. end
  6. end
  7. def f9583(s)
  8. s.size.odd? ? -1 : s.rgsub('()','').gsub(/\(\(|\)\)/,'*').size
  9. end
  10. a = %w[
  11. )
  12. ())())
  13. )()()(
  14. )))(((
  15. (())())((())(()(
  16. ())((())()))()(((()))()((((((((()()(()))
  17. ]
  18. p a.map {|s| [s, f9583(s)]}
  19.  
Success #stdin #stdout 0.01s 28216KB
stdin
Standard input is empty
stdout
[[")", -1], ["())())", 1], [")()()(", 2], [")))(((", 4], ["(())())((())(()(", 3], ["())((())()))()(((()))()((((((((()()(()))", 5]]