AtCoder Beginner Contest 005

Submission #1591139

Source codeソースコード

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

Task問題 D - おいしいたこ焼きの焼き方
User nameユーザ名 kumojima
Created time投稿日時
Language言語 Ruby (2.3.3)
Status状態 WA
Score得点 0
Source lengthソースコード長 770 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
Subtask1 0 / 50 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 0 / 50 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
rand0.txt WA
rand1.txt WA
rand2.txt WA
rand3.txt WA
rand4.txt WA
rand_max0.txt WA
rand_max1.txt WA
rand_max2.txt WA
rand_max3.txt WA
rand_max4.txt WA
s1.txt AC 7 ms 1788 KB
s2.txt WA
sub0.txt WA
sub1.txt WA
sub2.txt WA
sub_rand_max0.txt WA
sub_rand_max1.txt WA
sub_rand_max2.txt WA
sub_rand_max3.txt WA
sub_rand_min0.txt AC 7 ms 1788 KB