Submission #1591148


Source Code Expand

require 'pp'
N = gets.to_i
MAP = [nil] + N.times.map{ [nil] + gets.split.map(&:to_i) }
Q, *PS = readlines.map(&:to_i)

scores = Array.new(N*N + 1, 0)
sums = {}

N.downto(1) do |y1|
  N.downto(1) do |x1|
    y1.upto(N) do |y2|
      x1.upto(N) do |x2|
        sum = MAP[y1][x1]
        sum += sums[y1][x1+1][y2][x2] unless x1==x2
        sum += sums[y1+1][x1][y2][x1] unless y1==y2
        sums[y1] ||= {}
        sums[y1][x1] ||= {}
        sums[y1][x1][y2] ||= {}
        sums[y1][x1][y2][x2] = sum
        area = (x2-x1+1)*(y2-y1+1)
        scores[area] = sum if scores[area] < sum
      end
    end
  end
end

2.upto(N*N) do |i|
  scores[i] = scores[i-1] if scores[i] < scores[i-1]
end

PS.each do |pn|
  p scores[pn]
end

Submission Info

Submission Time
Task D - おいしいたこ焼きの焼き方
User yhara
Language Ruby (2.3.3)
Score 100
Code Size 758 Byte
Status AC
Exec Time 2043 ms
Memory 123900 KB

Judge Result

Set Name Subtask1 Subtask2
Score / Max Score 50 / 50 50 / 50
Status
AC × 18
AC × 20
Set Name Test Cases
Subtask1 sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt, s1.txt, s2.txt, sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt
Subtask2 rand0.txt, rand1.txt, rand2.txt, rand3.txt, rand4.txt, rand_max0.txt, rand_max1.txt, rand_max2.txt, rand_max3.txt, rand_max4.txt, s1.txt, s2.txt, sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt
Case Name Status Exec Time Memory
rand0.txt AC 1079 ms 70524 KB
rand1.txt AC 612 ms 40828 KB
rand2.txt AC 969 ms 64892 KB
rand3.txt AC 210 ms 15740 KB
rand4.txt AC 15 ms 2428 KB
rand_max0.txt AC 1994 ms 123900 KB
rand_max1.txt AC 2034 ms 123900 KB
rand_max2.txt AC 2043 ms 123900 KB
rand_max3.txt AC 2007 ms 123900 KB
rand_max4.txt AC 2005 ms 123900 KB
s1.txt AC 11 ms 2044 KB
s2.txt AC 11 ms 2044 KB
sub0.txt AC 11 ms 2044 KB
sub1.txt AC 11 ms 2044 KB
sub2.txt AC 11 ms 2044 KB
sub_rand_max0.txt AC 11 ms 2044 KB
sub_rand_max1.txt AC 11 ms 2044 KB
sub_rand_max2.txt AC 11 ms 2044 KB
sub_rand_max3.txt AC 11 ms 2044 KB
sub_rand_min0.txt AC 11 ms 4092 KB