94612024-02-22 08:57:33birozsFestés (50 pont)python3Time limit exceeded 0/50703ms59184 KiB
N,M = map(int,input().split())
soronkent = list(map(int,input().split()))

matrix = []
for Oszlop in range(M):
    sor = list(map(int,input().split()))
    matrix.append(sor)

if N == 2:
    #Mindkét sor festve
    eset = [sum(soronkent)]
    #Csak első sor festve
    osszeg = soronkent[0]
    for Oszlop in range(M):
        osszeg += min([matrix[Oszlop][2],matrix[Oszlop][1]])
    eset.append(osszeg)
    #Csak második sor festve
    osszeg = soronkent[1]
    for Oszlop in range(M):
        osszeg += min([matrix[Oszlop][0],matrix[Oszlop][1]])
    eset.append(osszeg)
    #Nincs sor festve
    osszeg = 0
    for Oszlop in range(N):
        osszeg += min([matrix[Oszlop][0]+matrix[Oszlop][2],matrix[Oszlop][1]])
    eset.append(osszeg)
    print(min(eset))
if N == 3:
    #Minden sor festve
    eset = [sum(soronkent)]
    tools = [[0],[1],[2],[0,1],[0,2],[1,2],[]]
    check = [[0,3,5],[0,4],[1,5],[2],[1,4]]
    for sor in tools:
        lista = []
        osszeg = 0
        for x in sor:
            osszeg += soronkent[x]
        lista.append(osszeg)
        for Oszlop in range(M):
            valami = []
            for y in check:
                bennevan = False
                for z in sor:
                    if z in y:
                        bennevan = True
                if not bennevan:
                    seged = []
                    for j in y:
                        seged.append(matrix[Oszlop][j])
                    valami.append(sum(seged))
            lista.append(min(valami))
        eset.append(sum(lista))                                      
    print(min(eset))
if N == 4:
    eset = [sum(soronkent)]
    tools = [[0],[1],[2],[3],[0,1],[0,2],[0,3],[1,2],[1,3],[2,3],[0,1,2],[1,2,3],[0,2,3],[0,1,3],[]]
    check = [[0,4,7,9],[1,7,9],[0,5,9],[0,4,8],[1,8],[0,6],[2,9],[3],[1,6],[1,5,9],[2,8],[0,5,8],[2,6]]
    for sor in tools:
        lista = []
        osszeg = 0
        for x in sor:
            osszeg += soronkent[x]
        lista.append(osszeg)
        for Oszlop in range(M):
            valami = []
            for y in check:
                bennevan = False
                for z in sor:
                    if z in y:
                        bennevan = True
                if not bennevan:
                    seged = []
                    for j in y:
                        seged.append(matrix[Oszlop][j])
                    valami.append(sum(seged))
            lista.append(min(valami))
        eset.append(sum(lista))                                      
    print(min(eset))

SubtaskSumTestVerdictTimeMemory
base0/50
1Accepted0/018ms12032 KiB
2Accepted0/019ms12108 KiB
3Time limit exceeded0/2703ms40264 KiB
4Wrong answer0/237ms12676 KiB
5Wrong answer0/3202ms13368 KiB
6Time limit exceeded0/2666ms10276 KiB
7Time limit exceeded0/2671ms56744 KiB
8Time limit exceeded0/2679ms56384 KiB
9Time limit exceeded0/2683ms56600 KiB
10Time limit exceeded0/2690ms56880 KiB
11Time limit exceeded0/2690ms57256 KiB
12Time limit exceeded0/2670ms53156 KiB
13Time limit exceeded0/2670ms53096 KiB
14Wrong answer0/2400ms59184 KiB
15Wrong answer0/3398ms59176 KiB
16Time limit exceeded0/3684ms40684 KiB
17Time limit exceeded0/2681ms41108 KiB
18Time limit exceeded0/3676ms40020 KiB
19Time limit exceeded0/2674ms49392 KiB
20Time limit exceeded0/2674ms53332 KiB
21Time limit exceeded0/2689ms56200 KiB
22Time limit exceeded0/2684ms56604 KiB
23Time limit exceeded0/2671ms57044 KiB
24Time limit exceeded0/2657ms55232 KiB
25Time limit exceeded0/2666ms58684 KiB