Submission #7267885


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
      puts [i, p, ans]
      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 : -1

Submission Info

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

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 1
WA × 2
AC × 3
WA × 19
TLE × 1
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 2 ms 636 KB
a02 WA 2 ms 636 KB
a03 AC 2 ms 636 KB
b04 WA 2 ms 636 KB
b05 WA 2 ms 2556 KB
b06 WA 2 ms 636 KB
b07 AC 2 ms 636 KB
b08 TLE 2107 ms 18928 KB
b09 AC 307 ms 9852 KB
b10 WA 1984 ms 19580 KB
b11 WA 1977 ms 17532 KB
b12 WA 564 ms 6524 KB
b13 WA 479 ms 4604 KB
b14 WA 176 ms 2812 KB
b15 WA 171 ms 2428 KB
b16 WA 30 ms 1276 KB
b17 WA 62 ms 3196 KB
b18 WA 383 ms 4220 KB
b19 WA 309 ms 3836 KB
b20 WA 33 ms 1404 KB
b21 WA 76 ms 1532 KB
b22 WA 8 ms 892 KB
b23 WA 12 ms 892 KB