Submission #45090600


Source Code Expand

h, w = gets.chomp.split.map(&:to_i)

top = {}
h.times do |i|
  has_cookies = false
  start_of_cookies = nil
  end_of_cookies = nil
  gets.chomp.chars.each_with_index do |v, j|
    is_cookie = v == '#'

    if is_cookie
      has_cookies = true
      start_of_cookies ||= [i, j]
      unless end_of_cookies.nil?
        # 一度クッキー列が切れた後に復活したらそこの左隣が食べたところ
        puts "#{i + 1} #{j}"
        exit
      end

      end_of_cookies = [i, j] if j == w - 1
    else
      end_of_cookies = [i, j - 1] if !start_of_cookies.nil? && end_of_cookies.nil?
    end
  end

  if has_cookies
    # クッキーの配置は2 * 2以上のサイズがあるので、食べた行も必ず1枚以上のクッキーがあるはず
    if top.empty?
      top[:left] = start_of_cookies
      top[:right] = end_of_cookies
      next
    end

    # 一番上の列と比べて両端が欠けてないかの検証
    if top[:left][1] != start_of_cookies[1]
      eaten = top[:left][1] < start_of_cookies[1] ? start_of_cookies : top[:left]
      puts "#{eaten[0] + 1} #{eaten[1]}"
      exit
    end

    if top[:right][1] != end_of_cookies[1]
      eaten = top[:right][1] < end_of_cookies[1] ? top[:right] : end_of_cookies
      puts "#{eaten[0] + 1} #{eaten[1] + 2}"
      exit
    end
  end
end

Submission Info

Submission Time
Task C - Snuke the Cookie Picker
User thatblue
Language Ruby (2.7.1)
Score 300
Code Size 1376 Byte
Status AC
Exec Time 104 ms
Memory 14324 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 23
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_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 03_corner_00.txt, 03_corner_01.txt, 03_corner_02.txt, 03_corner_03.txt, 03_corner_04.txt, 03_corner_05.txt, 03_corner_06.txt, 03_corner_07.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 56 ms 14156 KiB
00_sample_01.txt AC 57 ms 14220 KiB
00_sample_02.txt AC 55 ms 14220 KiB
01_handmade_00.txt AC 101 ms 14156 KiB
01_handmade_01.txt AC 98 ms 14060 KiB
01_handmade_02.txt AC 78 ms 14324 KiB
01_handmade_03.txt AC 57 ms 14100 KiB
02_random_00.txt AC 66 ms 14200 KiB
02_random_01.txt AC 67 ms 14236 KiB
02_random_02.txt AC 77 ms 14124 KiB
02_random_03.txt AC 91 ms 14100 KiB
02_random_04.txt AC 64 ms 14156 KiB
02_random_05.txt AC 70 ms 14040 KiB
02_random_06.txt AC 90 ms 14080 KiB
02_random_07.txt AC 79 ms 14168 KiB
03_corner_00.txt AC 95 ms 14016 KiB
03_corner_01.txt AC 82 ms 14188 KiB
03_corner_02.txt AC 62 ms 14116 KiB
03_corner_03.txt AC 76 ms 14204 KiB
03_corner_04.txt AC 104 ms 14192 KiB
03_corner_05.txt AC 103 ms 14272 KiB
03_corner_06.txt AC 57 ms 14160 KiB
03_corner_07.txt AC 57 ms 14024 KiB