Submission #632251

# Submission time Handle Problem Language Result Execution time Memory
632251 2022-08-19T18:34:21 Z karolb2011 Coins (LMIO19_monetos) Python 3
10 / 100
2000 ms 262144 KB
import sys
input = sys.stdin.readline
t,n,k1,k2=list(map(int,input().split()))
m=[]
for i in range(n):
    m.append(list(map(int,input().split())))
d=[[[1000000 for _ in range(n*n//2+1)]for _ in range(n+2)]for _ in range(n+1)]
p=[[[-1 for _ in range(n*n//2+1)]for _ in range(n+2)]for _ in range(n+1)]
d[n][0][0]=0
for i in reversed(range(n)):
    a=0
    for j in range(n+1):
        for k in range(n*n//2+1-j):
            if d[i][j][k+j]>d[i+1][j][k]+a:
                d[i][j][k+j]=d[i+1][j][k]+a
                p[i][j][k+j]=k
            if d[i+1][j][k]<d[i+1][j+1][k]:
                d[i+1][j+1][k]=d[i+1][j][k]
                p[i+1][j+1][k]=-1
        if j<n:
            a+=m[i][j]
v=[0 for _ in range(n)]
k=n*n//2
dm=1000000
for j in range(n+1):
    if d[0][j][k]<dm:
        dm=d[0][j][k]
        jj=j
j=jj
for i in range(n):
    while j>0 and p[i][j][k]<0:
        j-=1
    if j==0:
        break
    if p[i][j][k]>=0:
        v[i]=j
        k=p[i][j][k]
for i in range(n):
    for j in range(n):
        if v[i]>j:
            print(0,end=" ")
        else:
            print(1,end=" ")
    print()
# Verdict Execution time Memory Grader output
1 Correct 22 ms 3156 KB K = 17
2 Execution timed out 2083 ms 68952 KB Time limit exceeded
3 Runtime error 1411 ms 262144 KB Execution killed with signal 9
4 Runtime error 1406 ms 262144 KB Execution killed with signal 9
5 Runtime error 1480 ms 262144 KB Execution killed with signal 9
6 Runtime error 1426 ms 262144 KB Execution killed with signal 9
7 Runtime error 1409 ms 262144 KB Execution killed with signal 9
8 Runtime error 1460 ms 262144 KB Execution killed with signal 9
9 Runtime error 1393 ms 262144 KB Execution killed with signal 9
10 Runtime error 1384 ms 262144 KB Execution killed with signal 9