답안 #632329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
632329 2022-08-19T20:55:47 Z karolb2011 Coins (LMIO19_monetos) Python 3
68.4856 / 100
1958 ms 45068 KB
import sys
input = sys.stdin.readline
t,n,k1,k2=list(map(int,input().split()))
m=[]
if t<=2:
    sw=1
elif t in [3,4,6,7,10]:
    sw=60
else:
    sw=60
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
    di=d[i]
    dip=d[i+1]
    for j in range(nn+1):
        dij=di[j]
        dipj=dip[j]
        dipjp=dip[j+1]
        for k in range(nn*nn//2+1-j):
            if dij[k+j]>dipj[k]+a:
                dij[k+j]=dipj[k]+a
            if dipj[k]<dipjp[k]:
                dipjp[k]=dipj[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(nn):
    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):
    ss=""
    for j in range(nn):
        if v[i//sw]>j:
            
            ss+="0 "*sw
        else:
            ss+="1 "*sw
    ss+="\n"
    sys.stdout.write(ss)
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 3024 KB K = 17
2 Correct 1958 ms 45068 KB K = 576
3 Partially correct 56 ms 3156 KB K = 19223
4 Partially correct 66 ms 3100 KB K = 22136
5 Partially correct 59 ms 3184 KB K = 17891
6 Partially correct 56 ms 3148 KB K = 21642
7 Partially correct 57 ms 3160 KB K = 21948
8 Partially correct 53 ms 3152 KB K = 20115
9 Partially correct 55 ms 3152 KB K = 20861
10 Partially correct 66 ms 3180 KB K = 20415