-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17281.py
More file actions
66 lines (51 loc) · 1.53 KB
/
17281.py
File metadata and controls
66 lines (51 loc) · 1.53 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
import sys
input = sys.stdin.readline
inningNum = int(input())
iResult = [[] for _ in range(inningNum)]
for i in range(inningNum):
iResult[i] = list(map(int, input().split()))
def perm(arr, n):
result = []
if n > len(arr):
return result
if n == 1:
for i in arr:
result.append([i])
elif n > 1:
for i in range(len(arr)):
ans = [i for i in arr]
ans.remove(arr[i])
for p in perm(ans, n-1):
result.append([arr[i]] + p)
return result
runners = list(range(1, 9))
runnersPerm = perm(runners, 8)
maxScore = 0
for runnerList in runnersPerm:
score = 0
runnerList = list(runnerList)
tempRunnerList = runnerList[:3] + [0] + runnerList[3:]
idx = 0
for iNum in range(inningNum):
out = 0
bases = [False] * 3
while out != 3:
hit = iResult[iNum][tempRunnerList[idx]]
idx += 1
idx %= 9
if hit == 1:
score += bases[2]
bases = [True] + bases[:2]
elif hit == 2:
score += (bases[2] + bases[1])
bases = [False, True] + [bases[0]]
elif hit == 3:
score += (bases[2] + bases[1] + bases[0])
bases = [False, False, True]
elif hit == 4:
score += ((bases[2] + bases[1] + bases[0]) + 1)
bases = [False] * 3
elif hit == 0:
out += 1
maxScore = max(maxScore, score)
print(maxScore)