Submission #7266472


Source Code Expand

Copy
n = read_line.to_i
a = Array.new(n) { read_line.split.map { |v| v.to_i - 1 }.reverse }
ans = 0
update = Array.new(n) { |i| i }
time = Array.new(n, -1)
while !update.empty?
  n = [] of Int32
  update.each do |i|
    next if a[i].empty?
    next if time[i] == ans
    p = a[i][-1]
    next if time[p] == ans
    if a[p][-1] == i
      n << i
      n << p
      a[i].pop
      a[p].pop
      time[i] = time[p] = ans
    end
  end
  update = n
  ans += 1
end
puts a.all? { |p| p.empty? } ? ans : -1

Submission Info

Submission Time
Task E - League
User tomerun
Language Crystal (0.20.5)
Score 0
Code Size 519 Byte
Status WA
Exec Time 494 ms
Memory 13436 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 1
WA × 2
AC × 7
WA × 16
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23
Case Name Status Exec Time Memory
a01 WA 1 ms 636 KB
a02 WA 1 ms 636 KB
a03 AC 1 ms 636 KB
b04 WA 1 ms 636 KB
b05 WA 1 ms 636 KB
b06 WA 1 ms 636 KB
b07 AC 1 ms 636 KB
b08 WA 494 ms 9980 KB
b09 AC 306 ms 11772 KB
b10 WA 436 ms 11772 KB
b11 WA 440 ms 13436 KB
b12 WA 126 ms 4476 KB
b13 WA 107 ms 3196 KB
b14 AC 48 ms 2172 KB
b15 WA 40 ms 1788 KB
b16 AC 20 ms 1276 KB
b17 WA 16 ms 1020 KB
b18 WA 91 ms 2812 KB
b19 WA 75 ms 2812 KB
b20 AC 21 ms 1276 KB
b21 WA 19 ms 1020 KB
b22 AC 7 ms 892 KB
b23 WA 4 ms 764 KB