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)]
p=[[[-1 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
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<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):
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]
#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 |
20 ms |
3156 KB |
K = 17 |
2 |
Incorrect |
24 ms |
3228 KB |
K = 589 |
3 |
Partially correct |
599 ms |
14764 KB |
K = 18720 |
4 |
Partially correct |
619 ms |
14184 KB |
K = 21912 |
5 |
Partially correct |
582 ms |
13456 KB |
K = 17237 |
6 |
Partially correct |
589 ms |
14848 KB |
K = 20912 |
7 |
Partially correct |
562 ms |
14832 KB |
K = 21580 |
8 |
Partially correct |
592 ms |
14104 KB |
K = 19690 |
9 |
Partially correct |
602 ms |
13844 KB |
K = 20790 |
10 |
Partially correct |
647 ms |
13924 KB |
K = 20192 |