# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
632231 | karolb2011 | Coins (LMIO19_monetos) | Cpython 3 | 2081 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
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
j=n
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 |
---|---|---|---|---|
Fetching results... |