Submission #7263816


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]
    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 491 Byte
Status WA
Exec Time 492 ms
Memory 12924 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 12
WA × 11
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 AC 2 ms 636 KB
a02 AC 2 ms 636 KB
a03 AC 2 ms 636 KB
b04 AC 2 ms 636 KB
b05 WA 2 ms 636 KB
b06 WA 2 ms 636 KB
b07 AC 2 ms 636 KB
b08 WA 492 ms 10108 KB
b09 AC 306 ms 11004 KB
b10 WA 441 ms 12924 KB
b11 WA 440 ms 11900 KB
b12 WA 125 ms 4476 KB
b13 AC 105 ms 3196 KB
b14 AC 48 ms 2172 KB
b15 AC 39 ms 1788 KB
b16 AC 19 ms 1276 KB
b17 WA 15 ms 1020 KB
b18 WA 90 ms 2684 KB
b19 WA 73 ms 2556 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