Created
February 9, 2020 07:32
-
-
Save inspirit941/b8d161cf8f5ee31dd81f987d8576b2f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from itertools import permutations | |
end = int(sys.stdin.readline()) | |
inning = [list(map(int, sys.stdin.readline().split())) for _ in range(end)] | |
max_score = 0 | |
def game(line_ups): | |
hitter_idx = 0 | |
score = 0 | |
for each_inning in inning: | |
outcount = 0 | |
b1, b2, b3 = 0, 0, 0 | |
while outcount < 3: | |
# 이 변수 할당 하나가 시간초과를 만들었다. | |
# hit_type = each_inning[line_ups[hitter_idx]] | |
if each_inning[line_ups[hitter_idx]] == 0: | |
outcount += 1 | |
elif each_inning[line_ups[hitter_idx]] == 1: | |
score += b3 | |
b1, b2, b3 = 1, b1, b2 | |
elif each_inning[line_ups[hitter_idx]] == 2: | |
score += (b2 + b3) | |
b1, b2, b3 = 0, 1, b1 | |
elif each_inning[line_ups[hitter_idx]] == 3: | |
score += (b2 + b3 + b1) | |
b1, b2, b3 = 0, 0, 1 | |
elif each_inning[line_ups[hitter_idx]] == 4: | |
score += (1 + b1 + b2 + b3) | |
b1, b2, b3 = 0, 0, 0 | |
hitter_idx = (hitter_idx + 1) % 9 | |
return score | |
for line_ups in permutations(range(1,9), 8): | |
line_ups = list(line_ups[:3]) + [0] + list(line_ups[3:]) | |
max_score = max(max_score, game(line_ups)) | |
print(max_score) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment