Submission #632284

# Submission time Handle Problem Language Result Execution time Memory
632284 2022-08-19T19:48:30 Z karolb2011 Coins (LMIO19_monetos) Python 3
19.1271 / 100
545 ms 10124 KB
import sys
input = sys.stdin.readline
t,n,k1,k2=list(map(int,input().split()))
m=[]
if t<=1:
    sw=1
elif t==2:
    sw=5
else:
    sw=10
nn=n//sw
ssw=sw*sw
mm=[[0 for i in range(nn)]for j in range(nn)]
for i in range(n):
    mx=list(map(int,input().split()))
    for j in range(n):
        mm[i//sw][j//sw]+=mx[j]

d=[[[1000000 for _ in range(nn*nn//2+1)]for _ in range(nn+2)]for _ in range(nn+1)]
d[nn][0][0]=0
for i in reversed(range(nn)):
    a=0
    for j in range(nn+1):
        for k in range(nn*nn//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
            if d[i+1][j][k]<d[i+1][j+1][k]:
                d[i+1][j+1][k]=d[i+1][j][k]
        if j<nn:
            a+=mm[i][j]
v=[0 for _ in range(nn)]

k=nn*nn//2
dm=1000000
for j in range(nn+1):
    if d[0][j][k]<dm:
        dm=d[0][j][k]
        jj=j
j=jj
for i in range(n):
    if i>0:
        while j>0 and d[i][j-1][k]==d[i][j][k]:
            j-=1
    v[i]=j
    k-=j
    if j==0:
        break
    
#print(*v)
for i in range(n):
    for j in range(nn):
        if v[i//sw]>j:
            print("0 "*sw,end="")
        else:
            print("1 "*sw,end="")
    print()
# Verdict Execution time Memory Grader output
1 Correct 19 ms 3092 KB K = 17
2 Incorrect 24 ms 3132 KB K = 589
3 Runtime error 515 ms 9672 KB Execution failed because the return code was nonzero
4 Runtime error 500 ms 9420 KB Execution failed because the return code was nonzero
5 Runtime error 522 ms 8808 KB Execution failed because the return code was nonzero
6 Runtime error 505 ms 10112 KB Execution failed because the return code was nonzero
7 Partially correct 545 ms 10124 KB K = 21580
8 Runtime error 511 ms 9404 KB Execution failed because the return code was nonzero
9 Runtime error 528 ms 9092 KB Execution failed because the return code was nonzero
10 Runtime error 533 ms 9112 KB Execution failed because the return code was nonzero