Submission #8805265


Source Code Expand

n,d=map(int,input().split())
D=[list(map(int,input().split())) for _ in range(d)]
cost=[[0]*d for _ in range(3)]
c=[list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    for j in range(n):
        cost[(i+j)%3][c[i][j]-1]+=1
import itertools
ans=10**18
s=0
for p in itertools.permutations(range(1,d+1),3):
    for i in range(3):
        for j in range(d):
            s+=D[j][p[i]-1]*cost[i][j]
    if s<ans:
        ans=s    
    s=0
print(ans)

Submission Info

Submission Time
Task D - Good Grid
User pandai
Language PyPy3 (2.4.0)
Score 400
Code Size 481 Byte
Status AC
Exec Time 304 ms
Memory 45660 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 18
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
01.txt AC 304 ms 45660 KB
02.txt AC 265 ms 43100 KB
03.txt AC 209 ms 40684 KB
04.txt AC 213 ms 42332 KB
05.txt AC 161 ms 38256 KB
06.txt AC 277 ms 43740 KB
07.txt AC 280 ms 43740 KB
08.txt AC 278 ms 43740 KB
09.txt AC 207 ms 41692 KB
10.txt AC 192 ms 40176 KB
11.txt AC 194 ms 40560 KB
12.txt AC 204 ms 41692 KB
13.txt AC 268 ms 43740 KB
14.txt AC 240 ms 43228 KB
15.txt AC 279 ms 43612 KB
16.txt AC 240 ms 42204 KB
sample_01.txt AC 170 ms 38256 KB
sample_02.txt AC 162 ms 38256 KB