Submission #632232

#TimeUsernameProblemLanguageResultExecution timeMemory
632232karolb2011Coins (LMIO19_monetos)Cpython 3
0 / 100
2082 ms262144 KiB
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 timeMemoryGrader output
Fetching results...