Submission #68947172


Source Code Expand

q = gets.to_i
queries = Array.new(q) { gets.split.map!(&:to_i) }

h = { 0 => nil }

k = 0
queries.each do |t, x, y|
  k += 1

  case t
  when 1
    h[k] = h[x]
    h[x] = k
  when 2
    i = x
    j = y
    s = 0
    t = 0
    while true
      i = h[i]
      j = h[j]
      if i == y
        t = -1
        break
      end
      if j == x
        s = -1
        break
      end
      s += (i || 0)
      t += (j || 0)
    end

    if s >= 0
      puts s
      h[x] = y
    else
      puts t
      h[y] = x
    end
  else
    raise "Invalid type: #{t}"
  end
end

Submission Info

Submission Time
Task F - Erase between X and Y
User hmmnrst
Language Ruby (ruby 3.2.2)
Score 525
Code Size 605 Byte
Status AC
Exec Time 794 ms
Memory 77136 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 3
AC × 36
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 42 ms 17148 KiB
00_sample_01.txt AC 42 ms 17116 KiB
00_sample_02.txt AC 42 ms 17188 KiB
01_random_00.txt AC 739 ms 51560 KiB
01_random_01.txt AC 781 ms 54248 KiB
01_random_02.txt AC 775 ms 55840 KiB
01_random_03.txt AC 794 ms 59184 KiB
01_random_04.txt AC 788 ms 60204 KiB
01_random_05.txt AC 772 ms 60996 KiB
01_random_06.txt AC 771 ms 65644 KiB
01_random_07.txt AC 779 ms 66040 KiB
01_random_08.txt AC 783 ms 66676 KiB
01_random_09.txt AC 751 ms 67652 KiB
01_random_10.txt AC 748 ms 66276 KiB
01_random_11.txt AC 757 ms 77136 KiB
01_random_12.txt AC 731 ms 72900 KiB
01_random_13.txt AC 723 ms 69264 KiB
01_random_14.txt AC 694 ms 71412 KiB
01_random_15.txt AC 722 ms 68084 KiB
01_random_16.txt AC 679 ms 67304 KiB
01_random_17.txt AC 652 ms 67256 KiB
01_random_18.txt AC 613 ms 67404 KiB
01_random_19.txt AC 613 ms 68204 KiB
01_random_20.txt AC 573 ms 67288 KiB
02_random2_00.txt AC 676 ms 69532 KiB
02_random2_01.txt AC 642 ms 67932 KiB
02_random2_02.txt AC 592 ms 67928 KiB
02_random2_03.txt AC 567 ms 67636 KiB
02_random2_04.txt AC 571 ms 67548 KiB
03_handmade_00.txt AC 42 ms 17124 KiB
03_handmade_01.txt AC 549 ms 67480 KiB
03_handmade_02.txt AC 529 ms 67476 KiB
03_handmade_03.txt AC 610 ms 67672 KiB
03_handmade_04.txt AC 715 ms 62324 KiB
03_handmade_05.txt AC 705 ms 62132 KiB
03_handmade_06.txt AC 670 ms 60232 KiB