Submission #2212577


Source Code Expand

N = int(input())
D = [0]*N
for i in range(N):
    D[i] = [int(x) for x in input().split()]
Q = int(input())
P = [int(input()) for i in range(Q)]

max_values = [0 for i in range(N*N+1)]

taste = [[0 for i in range(N)] for j in range(N)]
taste[0][0] = D[0][0]
for i in range(1, N):
    taste[0][i] = D[0][i] + taste[0][i-1]
    taste[i][0] = D[i][0] + taste[i-1][0]

for i in range(1,N):
    for j in range(1,N):
        taste[i][j] = taste[i-1][j] + taste[i][j-1] - taste[i-1][j-1] + D[i][j]

for si in range(N):
    for sj in range(N):
        for ei in range(si, N):
            for ej in range(sj, N):
                row = 0 if sj == 0 else taste[ei][sj-1]
                col = 0 if si == 0 else taste[si-1][ej]
                mid = 0 if si == 0 or sj == 0 else taste[si-1][sj-1] 

                v = mid - col - row + taste[ei][ej]
                size = abs(ei-si+1)*abs(ej-sj+1)
                # print(si, sj, ei, ej, size, v, mid , col , row, taste[ei][ej])
                # print(si, sj, ei, ej, size, v)
                max_values[size] = max(max_values[size], v)

for p in P:
    print(max(max_values[:p+1]))

Submission Info

Submission Time
Task D - おいしいたこ焼きの焼き方
User akiyama_k
Language Python (3.4.3)
Score 100
Code Size 1157 Byte
Status AC
Exec Time 2369 ms
Memory 3572 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 1129 ms 3188 KB
rand1.txt AC 691 ms 3316 KB
rand2.txt AC 1125 ms 3444 KB
rand3.txt AC 230 ms 3188 KB
rand4.txt AC 22 ms 3064 KB
rand_max0.txt AC 2190 ms 3572 KB
rand_max1.txt AC 2194 ms 3572 KB
rand_max2.txt AC 2369 ms 3572 KB
rand_max3.txt AC 2109 ms 3572 KB
rand_max4.txt AC 2218 ms 3572 KB
s1.txt AC 17 ms 3064 KB
s2.txt AC 17 ms 3188 KB
sub0.txt AC 18 ms 3188 KB
sub1.txt AC 18 ms 3064 KB
sub2.txt AC 18 ms 3188 KB
sub_rand_max0.txt AC 18 ms 3188 KB
sub_rand_max1.txt AC 18 ms 3064 KB
sub_rand_max2.txt AC 18 ms 3188 KB
sub_rand_max3.txt AC 18 ms 3188 KB
sub_rand_min0.txt AC 17 ms 3064 KB