Submission #2657877
Source Code Expand
from itertools import product from collections import Counter n, c = map(int, input().split()) color_costs = [list(map(int, input().split())) for _ in range(c)] matrix = [list(map(int, input().split())) for _ in range(n)] colord = {(i, j):cost for i, row in enumerate(color_costs) for j, cost in enumerate(row)} res = [] for n in range(3): color_count = Counter(c-1 for i, row in enumerate(matrix) for j, c in enumerate(row) if (i + j) % 3 == n) def color_cost(color): return sum(colord[ccolor, color] * ccount for ccolor, ccount in color_count.items()) cx = [(color, color_cost(color)) for color in range(c)] sorted_by_cost = sorted(cx, key=lambda x:x[1]) cheapest3 = sorted_by_cost[:3] res.append(cheapest3) color_pickss = product(*res) filtered_unique = (picks for picks in color_pickss if len(set(x[0] for x in picks)) == 3) costs = (sum(x[1] for x in picks) for picks in filtered_unique) print(min(costs))
Submission Info
Submission Time | |
---|---|
Task | D - Good Grid |
User | zehnpaard |
Language | Python (3.4.3) |
Score | 400 |
Code Size | 1037 Byte |
Status | AC |
Exec Time | 202 ms |
Memory | 5996 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
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 | 190 ms | 5740 KB |
02.txt | AC | 152 ms | 5228 KB |
03.txt | AC | 21 ms | 3436 KB |
04.txt | AC | 71 ms | 3948 KB |
05.txt | AC | 21 ms | 3316 KB |
06.txt | AC | 191 ms | 5996 KB |
07.txt | AC | 202 ms | 5996 KB |
08.txt | AC | 191 ms | 5996 KB |
09.txt | AC | 63 ms | 3948 KB |
10.txt | AC | 37 ms | 3564 KB |
11.txt | AC | 53 ms | 3692 KB |
12.txt | AC | 76 ms | 4076 KB |
13.txt | AC | 187 ms | 5484 KB |
14.txt | AC | 163 ms | 5228 KB |
15.txt | AC | 190 ms | 5868 KB |
16.txt | AC | 91 ms | 4332 KB |
sample_01.txt | AC | 21 ms | 3316 KB |
sample_02.txt | AC | 21 ms | 3316 KB |