Submission #2207868


Source Code Expand

N = gets.to_i
yakiki = Array.new(N)
for i in 0..N-1 do
  d = gets.split(" ").map { |item| item.to_i }
  yakiki[i] = d
end

# 以下解説通り

migisita = Array.new(N+1) { Array.new(N+1) {0} } #右下までの長方形内部の合計値
for i in 1..N do
  for j in 1..N do
    if i == 1 && j == 1
      migisita[N-i][N-j] = yakiki[N-1][N-1]
    elsif j == 1
      migisita[N-i][N-j] = migisita[N-i+1][N-1] + yakiki[N-i][N-j]
    elsif i == 1
      migisita[N-i][N-j] = migisita[N-i][N-j+1] + yakiki[N-i][N-j]
    else
      migisita[N-i][N-j] = migisita[N-i][N-j+1] + migisita[N-i+1][N-j] - migisita[N-i+1][N-j+1] + yakiki[N-i][N-j]
    end
  end
end

tyoho = Array.new(N+1) { Array.new(N+1) {0} } #右下までの長方形の面積
for i in 1..N do
  for j in 1..N do
    if j == 1
      tyoho[N-i][N-j] = i
    elsif i == 1
      tyoho[N-i][N-j] = j
    else
      tyoho[N-i][N-j] = tyoho[N-i][N-j+1] + tyoho[N-i+1][N-j] - tyoho[N-i+1][N-j+1] + 1
    end
  end
end

oisisa = Array.new(N**2){0}

for a in 0..N-1 do #始点y
  for b in 0..N-1 do #始点x
    for c in 0..N-1 do #終点y
      for d in 0..N-1 do #終点x
        menseki = tyoho[a][b] - tyoho[c+1][b] - tyoho[a][d+1] + tyoho[c+1][d+1]
        gokei = migisita[a][b] - migisita[c+1][b] - migisita[a][d+1] + migisita[c+1][d+1]
        if oisisa[menseki-1] < gokei
          oisisa[menseki-1] = gokei
        end
      end
    end
  end
end

for i in 1..N**2-1 do
  if oisisa[i] < oisisa[i-1]
    oisisa[i] = oisisa[i-1]
  end
end

Q = gets.to_i
tenin = []
for i in 0..Q-1 do
  pi = gets.to_i
  tenin[i] = pi
end

for i in 0..Q-1 do
  puts oisisa[tenin[i]-1]
end


Submission Info

Submission Time
Task D - おいしいたこ焼きの焼き方
User inuneko6928
Language Ruby (2.3.3)
Score 100
Code Size 1700 Byte
Status AC
Exec Time 3681 ms
Memory 2044 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 1971 ms 1916 KB
rand1.txt AC 1095 ms 1916 KB
rand2.txt AC 1808 ms 1916 KB
rand3.txt AC 368 ms 2044 KB
rand4.txt AC 14 ms 1788 KB
rand_max0.txt AC 3612 ms 1916 KB
rand_max1.txt AC 3599 ms 1916 KB
rand_max2.txt AC 3645 ms 1916 KB
rand_max3.txt AC 3629 ms 1916 KB
rand_max4.txt AC 3681 ms 1916 KB
s1.txt AC 7 ms 1788 KB
s2.txt AC 7 ms 1788 KB
sub0.txt AC 7 ms 1788 KB
sub1.txt AC 7 ms 1788 KB
sub2.txt AC 8 ms 1788 KB
sub_rand_max0.txt AC 8 ms 1788 KB
sub_rand_max1.txt AC 8 ms 1788 KB
sub_rand_max2.txt AC 8 ms 1788 KB
sub_rand_max3.txt AC 8 ms 1788 KB
sub_rand_min0.txt AC 7 ms 1788 KB