Submission #48035830


Source Code Expand

n, t_dash = gets.chomp.split
n = n.to_i
t_dash_size = t_dash.size

def diff_str(shorter, longer)
  shorter_index = 0
  shorter_size = shorter.size
  longer_index = 0
  longer_size = longer.size
  diff_size = 0

  while shorter_index < shorter_size && longer_index < longer_size
    unless shorter[shorter_index] == longer[longer_index]
      diff_size += 1
      longer_index += 1
      next
    end

    shorter_index += 1
    longer_index += 1
  end

  diff_size.zero? ? 1 : diff_size
end

candidates = []
n.times do |index|
  no = index + 1
  candidate = gets.chomp

  if candidate == t_dash
    candidates << no
  elsif candidate.size == t_dash.size
    # 異なっている文字が1字だけであるかを検証
    char_diff = 0
    t_dash_size.times do |char_index|
      char_diff += 1 unless candidate[char_index] == t_dash[char_index]
    end
    candidates << no if char_diff == 1
  elsif candidate.size == t_dash.size + 1
    # 余計な文字が1文字挿入されている可能性がある
    candidates << no if diff_str(t_dash, candidate) == 1
  elsif candidate.size + 1 == t_dash.size
    # 1文字足りない可能性がある
    candidates << no if diff_str(candidate, t_dash) == 1
  end
end

puts candidates.size
puts candidates.join ' '

Submission Info

Submission Time
Task C - Error Correction
User thatblue
Language Ruby (ruby 3.2.2)
Score 300
Code Size 1314 Byte
Status AC
Exec Time 274 ms
Memory 22672 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 32
Set Name Test Cases
Sample example0.txt, example1.txt, example2.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, example0.txt, example1.txt, example2.txt
Case Name Status Exec Time Memory
000.txt AC 124 ms 18088 KiB
001.txt AC 45 ms 19668 KiB
002.txt AC 120 ms 19588 KiB
003.txt AC 120 ms 19644 KiB
004.txt AC 107 ms 19944 KiB
005.txt AC 107 ms 19816 KiB
006.txt AC 274 ms 22672 KiB
007.txt AC 209 ms 19908 KiB
008.txt AC 157 ms 18792 KiB
009.txt AC 125 ms 17992 KiB
010.txt AC 108 ms 17736 KiB
011.txt AC 100 ms 17228 KiB
012.txt AC 96 ms 17612 KiB
013.txt AC 94 ms 17440 KiB
014.txt AC 93 ms 17512 KiB
015.txt AC 93 ms 17660 KiB
016.txt AC 96 ms 17540 KiB
017.txt AC 95 ms 17416 KiB
018.txt AC 94 ms 17816 KiB
019.txt AC 92 ms 17764 KiB
020.txt AC 97 ms 18160 KiB
021.txt AC 103 ms 18228 KiB
022.txt AC 110 ms 18284 KiB
023.txt AC 81 ms 18248 KiB
024.txt AC 44 ms 18348 KiB
025.txt AC 45 ms 19840 KiB
026.txt AC 194 ms 18884 KiB
027.txt AC 192 ms 18864 KiB
028.txt AC 193 ms 18804 KiB
example0.txt AC 43 ms 16840 KiB
example1.txt AC 43 ms 17124 KiB
example2.txt AC 43 ms 17148 KiB