-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17135.py
More file actions
88 lines (56 loc) · 1.72 KB
/
17135.py
File metadata and controls
88 lines (56 loc) · 1.72 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
80
81
82
83
84
85
86
87
88
from itertools import combinations
import copy
def move_enemy():
global temp_board
new_board = [[] for _ in range(n)]
new_board[0] = [0] * m
for i in range(1, n):
new_board[i] = temp_board[i - 1]
temp_board = new_board
def find_enemy(archer_col, d):
enemies = []
archer_pos = (n, archer_col)
for i in range(n):
for j in range(m):
if temp_board[i][j] == 1:
dist = abs(i - n) + abs(j - archer_col)
if dist <= d:
enemies.append((dist, i, j))
enemies.sort(key=lambda x: (x[0], x[2]))
if enemies:
return enemies[0]
return (-1, -1, -1)
def attack_enemy(archer_pos):
global temp_count
to_attack = []
for a_c in archer_pos:
to_attack.append(find_enemy(a_c, d))
# print(to_attack)
for enemy in to_attack:
if enemy == (-1, -1, -1):
continue
dist, x, y = enemy
if temp_board[x][y] == 0:
continue
temp_board[x][y] = 0
temp_count += 1
n, m, d = map(int, input().split())
board = [list(map(int, input().split())) for _ in range(n)]
max_count = 0
for archer_index in combinations(range(m), 3):
# print(f"****{archer_index}****")
enemy_num = sum([sum(row) for row in board])
temp_count = 0
temp_board = copy.deepcopy(board)
while enemy_num > 0:
attack_enemy(archer_index)
# print("**after attack**")
# for b in temp_board:
# print(b)
move_enemy()
# print("**after move**")
# for b in temp_board:
# print(b)
enemy_num = sum([sum(row) for row in temp_board])
max_count = max(max_count, temp_count)
print(max_count)