-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path21608.py
More file actions
79 lines (52 loc) · 1.65 KB
/
21608.py
File metadata and controls
79 lines (52 loc) · 1.65 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
def find_loc(student):
candi = []
for i in range(n):
for j in range(n):
if class_room[i][j] == 0:
like_num = empty_num = 0
for k in range(4):
nx = i + dx[k]
ny = j + dy[k]
if 0 <= nx < n and 0 <= ny < n:
if class_room[nx][ny] in like_list[student]:
like_num += 1
elif class_room[nx][ny] == 0:
empty_num += 1
candi.append((-like_num, -empty_num, i, j))
candi.sort()
# print(student_num)
# print(candi)
l, e, x, y = candi[0]
class_room[x][y] = student
def cal_score():
global score
for i in range(n):
for j in range(n):
like_num = 0
student = class_room[i][j]
for k in range(4):
nx = i + dx[k]
ny = j + dy[k]
if 0 <= nx < n and 0 <= ny < n:
if class_room[nx][ny] in like_list[student]:
like_num += 1
if like_num == 1:
score += 1
elif like_num == 2:
score += 10
elif like_num == 3:
score += 100
elif like_num == 4:
score += 1000
n = int(input())
class_room = [[0] * n for _ in range(n)]
like_list = [[] for _ in range(n ** 2 + 1)]
for _ in range(n**2):
student_num, *like = list(map(int, input().split()))
like_list[student_num] = like
find_loc(student_num)
score = 0
cal_score()
print(score)