Submission #1591139


Source Code Expand

N = gets.to_i
D = N.times.map do
  gets.split.map(&:to_i)
end
Q = gets.to_i
P = Q.times.map do
  Math.sqrt(gets.to_i).to_i
end

memo = []

P.each do |p|
  if memo[p]
    puts memo[p]
    next
  end

  # 行方向の圧縮
  a = Array.new(N) do
    Array.new(N - p + 1, 0)
  end
  N.times do |i|
    a[i][0] = D[i][0, p].inject(:+)
    (N - p).times do |j|
      a[i][j + 1] = a[i][j] + D[i][j + p] - D[i][j]
    end
  end

  # 列方向の圧縮
  b = Array.new(N - p + 1) do
    Array.new(p, 0)
  end
  (N - p + 1).times do |i|
    b[0][i] = a[0, p].map { |c| c[i] }.inject(:+)
    (N - p).times do |j|
      b[j + 1][i] = b[j][i] + a[j + p][i] - a[j][i]
    end
  end

  max = b.map(&:max).max
  memo[p] = max
  puts max
end

Submission Info

Submission Time
Task D - おいしいたこ焼きの焼き方
User kumojima
Language Ruby (2.3.3)
Score 0
Code Size 770 Byte
Status WA
Exec Time 48 ms
Memory 2812 KB

Judge Result

Set Name Subtask1 Subtask2
Score / Max Score 0 / 50 0 / 50
Status
AC × 3
WA × 15
AC × 2
WA × 18
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 WA 29 ms 2044 KB
rand1.txt WA 24 ms 2044 KB
rand2.txt WA 32 ms 2684 KB
rand3.txt WA 15 ms 1916 KB
rand4.txt WA 7 ms 1788 KB
rand_max0.txt WA 48 ms 2812 KB
rand_max1.txt WA 46 ms 2684 KB
rand_max2.txt WA 48 ms 2812 KB
rand_max3.txt WA 48 ms 2812 KB
rand_max4.txt WA 48 ms 2812 KB
s1.txt AC 7 ms 1788 KB
s2.txt WA 7 ms 1788 KB
sub0.txt WA 7 ms 1788 KB
sub1.txt WA 7 ms 1788 KB
sub2.txt WA 7 ms 1788 KB
sub_rand_max0.txt WA 7 ms 1788 KB
sub_rand_max1.txt WA 7 ms 1788 KB
sub_rand_max2.txt WA 7 ms 1788 KB
sub_rand_max3.txt WA 7 ms 1788 KB
sub_rand_min0.txt AC 7 ms 1788 KB