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=6
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):
for j in range(nn):
if v[i//sw]>j:
print("0 "*sw,end="")
else:
print("1 "*sw,end="")
print()
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3028 KB |
K = 17 |
2 |
Incorrect |
21 ms |
3116 KB |
K = 589 |
3 |
Partially correct |
1904 ms |
55976 KB |
K = 18672 |
4 |
Execution timed out |
2033 ms |
54236 KB |
Time limit exceeded |
5 |
Partially correct |
1960 ms |
49112 KB |
K = 17199 |
6 |
Execution timed out |
2041 ms |
58724 KB |
Time limit exceeded |
7 |
Partially correct |
1962 ms |
57208 KB |
K = 21498 |
8 |
Partially correct |
1959 ms |
53064 KB |
K = 19635 |
9 |
Execution timed out |
2059 ms |
50692 KB |
Time limit exceeded |
10 |
Partially correct |
1989 ms |
51140 KB |
K = 20181 |