Submission #1303440


Source Code Expand

I,T,F,r=int,True,False,range
t=input().split()
H,W,K,A,a=I(t[0]),I(t[1]),I(t[2]),[],[]
s=[[I(i) for i in input()]for i in r(H)]
e=[[T if s[i][j]>4 else F for j in r(W)] for i in r(H)]
for i1 in r(H):
	for j1 in r(W):
		if e[i1][j1]==T:
			l,p,u=[[i1,j1]],s[i1][j1],[[F for i in r(W)] for j in r(H)]
			u[i1][j1]=T
			for m in r(K-1):
				M,P=-1,[-1,-1]
				for L in l:
					if 0<L[0]and s[L[0]-1][L[1]]>M and u[L[0]-1][L[1]]==F:M,P=s[L[0]-1][L[1]],[L[0]-1,L[1]]
					if L[0]<H-1 and s[L[0]+1][L[1]]>M and u[L[0]+1][L[1]]==F:M,P=s[L[0]+1][L[1]],[L[0]+1,L[1]]
					if 0<L[1]and s[L[0]][L[1]-1]>M and u[L[0]][L[1]-1]==F:M,P=s[L[0]][L[1]-1],[L[0],L[1]-1]
					if L[1]<W-1 and s[L[0]][L[1]+1]>M and u[L[0]][L[1]+1]==F:M,P=s[L[0]][L[1]+1],[L[0],L[1]+1]
				if M<1:break
				u[P[0]][P[1]]=T
				p*=s[P[0]][P[1]]
				l+=[P]
			else:A.append([p,l])
A.sort()
u=[[F for i in r(W)] for j in r(H)]
for d in reversed(A):
	L=d[1]
	for g in L:
		if u[g[0]][g[1]]:break
	else:
		a+=[L]
		for g in L:u[g[0]][g[1]]=True
print(len(a))
for i in a:
	for j in r(K):print(str(i[j][0]+1)+" "+str(i[j][1]+1))

Submission Info

Submission Time
Task A - Multiple Pieces
User toma25
Language Python (3.4.3)
Score 850577
Code Size 1115 Byte
Status AC
Exec Time 256 ms
Memory 4572 KB

Judge Result

Set Name test_01 test_02 test_03 test_04 test_05 test_06 test_07 test_08 test_09 test_10
Score / Max Score 87370 / 1343058 81486 / 1343058 85689 / 1343058 81984 / 1343058 89098 / 1343058 81613 / 1343058 87696 / 1343058 81213 / 1343058 88509 / 1343058 85919 / 1343058
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
test_01 subtask_01_01.txt
test_02 subtask_01_02.txt
test_03 subtask_01_03.txt
test_04 subtask_01_04.txt
test_05 subtask_01_05.txt
test_06 subtask_01_06.txt
test_07 subtask_01_07.txt
test_08 subtask_01_08.txt
test_09 subtask_01_09.txt
test_10 subtask_01_10.txt
Case Name Status Exec Time Memory
subtask_01_01.txt AC 234 ms 4572 KB
subtask_01_02.txt AC 234 ms 4572 KB
subtask_01_03.txt AC 239 ms 4572 KB
subtask_01_04.txt AC 233 ms 4572 KB
subtask_01_05.txt AC 237 ms 4572 KB
subtask_01_06.txt AC 237 ms 4572 KB
subtask_01_07.txt AC 237 ms 4572 KB
subtask_01_08.txt AC 231 ms 4572 KB
subtask_01_09.txt AC 256 ms 4572 KB
subtask_01_10.txt AC 238 ms 4572 KB