이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
from heapq import heappush, heappop
from collections import namedtuple
from copy import copy
Shard = namedtuple('Shard', ['score', 'best', 'forced', 'forbitten'])
n, k, c = [int(x) for x in input().split(' ')]
scores = [[int(x) for x in input().split(' ')] for i in range(n)]
def pairwise_max(a, b):
return [max(a[i], b[i]) for i in range(len(a))]
def evaluate_shard(shard):
best = []
event_best = [0] * k
for x in shard.forced:
best.append(x)
for i in range(len(shard.forced), k):
best.append(-1)
for j in range(n):
if not shard.forbitten[j] and j not in best:
if best[i] == -1 or scores[j][i] > scores[best[i]][i]:
best[i] = j
for c in best:
event_best = pairwise_max(event_best, scores[c])
return(Shard(-sum(event_best), best, shard.forced, shard.forbitten))
heap = [Shard(0, [], [], [False]*n)]
heap[0] = evaluate_shard(heap[0])
results = []
while len(results) < c:
top = heappop(heap)
results.append(-top.score)
new_forced = copy(top.forced)
new_forbitten = copy(top.forbitten)
for i in range(len(top.forced), k):
new_forbitten[top.best[i]] = True
new_shard = evaluate_shard(Shard(0, [], copy(new_forced), copy(new_forbitten)))
if -1 not in new_shard.best:
heappush(heap, new_shard)
new_forced.append(top.best[i])
print(results[c-1])
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |