Submission #1165920


Source Code Expand

temp=input().split()
H,W,K,tempAns,ans=int(temp[0]),int(temp[1]),int(temp[2]),[],[]
s=[[int(i) for i in input()]for i in range(H)]
existHigh=[[True if s[i][j]>6 else False for j in range(W)] for i in range(H)]
for i1 in range(H):
	for j1 in range(W):
		if existHigh[i1][j1]==True:
			place,point,used=[[i1,j1]],s[i1][j1],[[False for i in range(W)] for j in range(H)]
			used[i1][j1]=True
			for temp0 in range(K-1):
				tempMax,tempMaxPlace=-1,[-1,-1]
				for tempPlace in place:
					if 0<tempPlace[0]:
						if s[tempPlace[0]-1][tempPlace[1]]>tempMax and used[tempPlace[0]-1][tempPlace[1]]==False:
							tempMax,tempMaxPlace=s[tempPlace[0]-1][tempPlace[1]],[tempPlace[0]-1,tempPlace[1]]
					if tempPlace[0]<H-1:
						if s[tempPlace[0]+1][tempPlace[1]]>tempMax and used[tempPlace[0]+1][tempPlace[1]]==False:
							tempMax,tempMaxPlace=s[tempPlace[0]+1][tempPlace[1]],[tempPlace[0]+1,tempPlace[1]]
					if 0<tempPlace[1]:
						if s[tempPlace[0]][tempPlace[1]-1]>tempMax and used[tempPlace[0]][tempPlace[1]-1]==False:
							tempMax,tempMaxPlace=s[tempPlace[0]][tempPlace[1]-1],[tempPlace[0],tempPlace[1]-1]
					if tempPlace[1]<W-1:
						if s[tempPlace[0]][tempPlace[1]+1]>tempMax and used[tempPlace[0]][tempPlace[1]+1]==False:
							tempMax,tempMaxPlace=s[tempPlace[0]][tempPlace[1]+1],[tempPlace[0],tempPlace[1]+1]
				if tempMax<1: break
				if used[tempMaxPlace[0]][tempMaxPlace[1]]==False: used[tempMaxPlace[0]][tempMaxPlace[1]]=True
				point*=s[tempMaxPlace[0]][tempMaxPlace[1]]
				place+=[tempMaxPlace]
			else:
				tempAns.append([point,place])
tempAns.sort(key=lambda x:x[0])
used=[[False for i in range(W)] for j in range(H)]
for data in reversed(tempAns):
	place=data[1]
	for grid in place:
		if used[grid[0]][grid[1]]: break
	else:
		ans.append(place)
		for grid in place: used[grid[0]][grid[1]]=True
print(len(ans))
for i in ans:
	for j in range(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 833453
Code Size 1956 Byte
Status AC
Exec Time 141 ms
Memory 4056 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 86902 / 1343058 80287 / 1343058 85208 / 1343058 80441 / 1343058 88086 / 1343058 78936 / 1343058 83072 / 1343058 79639 / 1343058 87491 / 1343058 83391 / 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 139 ms 4056 KB
subtask_01_02.txt AC 135 ms 4056 KB
subtask_01_03.txt AC 139 ms 4056 KB
subtask_01_04.txt AC 135 ms 4056 KB
subtask_01_05.txt AC 141 ms 4056 KB
subtask_01_06.txt AC 135 ms 4056 KB
subtask_01_07.txt AC 140 ms 4056 KB
subtask_01_08.txt AC 136 ms 4056 KB
subtask_01_09.txt AC 137 ms 4056 KB
subtask_01_10.txt AC 139 ms 4056 KB