-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path21608.py
63 lines (51 loc) · 1.44 KB
/
21608.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import sys
input = sys.stdin.readline
n = int(input())
graph = [[0] * n for _ in range(n)]
nums = [0] * (n**2 + 1)
comelist = []
t = n**2
for i in range(t):
s = list(map(int, input().split()))
comelist.append(s[0])
nums[s[0]] = s[1:]
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
ans = []
for x in comelist:
fx = 0
fy = 0
likemax = -1
zeromax = -1
for i in range(n):
for j in range(n):
if graph[i][j] == 0:
likecnt = 0
zerocnt = 0
for d in range(4):
nx = i + dx[d]
ny = j + dy[d]
if 0 <= nx < n and 0<= ny < n:
if graph[nx][ny] in nums[x]:
likecnt += 1
if graph[nx][ny] == 0:
zerocnt += 1
if (likecnt == likemax and zerocnt > zeromax) or likecnt > likemax :
likemax = likecnt
zeromax = zerocnt
fx = i
fy = j
graph[fx][fy] = x
ansbox = [0,1,10,100,1000]
total = 0
for i in range(n):
for j in range(n):
anscnt = 0
for d in range(4):
nx = i + dx[d]
ny = j + dy[d]
if 0 <= nx < n and 0 <= ny < n:
if graph[nx][ny] in nums[graph[i][j]]:
anscnt += 1
total += ansbox[anscnt]
print(total)