from itertools import permutations
import sys
input = sys.stdin.readline
def play(entry):
out_count = 0
innings = 0
cu_player_ind = 0
# 1루,2루,3루
score = 0
base1,base2,base3 = 0,0,0
while innings < N:
while out_count<3:
if arr[innings][entry[cu_player_ind]-1] == 0:
out_count += 1
elif arr[innings][entry[cu_player_ind]-1] == 1:
score += base3
base1,base2,base3 = 1,base1,base2
elif arr[innings][entry[cu_player_ind]-1] == 2:
score += (base2+base3)
base1,base2,base3 = 0,1,base1
elif arr[innings][entry[cu_player_ind]-1] == 3:
score += (base1+base2+base3)
base1,base2,base3 = 0,0,1
else:
score = score + base1+base2+base3 + 1
base1,base2,base3 = 0,0,0
cu_player_ind = (cu_player_ind+1)%9
out_count = 0
base1,base2,base3 = 0,0,0
innings += 1
return score
N = int(input())
arr = [list(map(int,input().split())) for _ in range(N)]
result = 0
for _players in permutations(range(2,10)):
_players = list(_players)
players = _players[:3]+[1] + _players[3:]
temp = play(players)
if result <temp:
result = temp
print(result)
from itertools import permutations
import sys
input = sys.stdin.readline
N = int(input())
arr = [list(map(int,input().split())) for _ in range(N)]
result = 0
for _players in permutations(range(2,10)):
_players = list(_players)
players = _players[:3]+[1] + _players[3:]
cu_player_ind = 0
# 1루,2루,3루
score = 0
for innings in arr:
out_count = 0
base1,base2,base3 = 0,0,0
while out_count<3:
if innings[players[cu_player_ind]-1] == 0:
out_count += 1
elif innings[players[cu_player_ind]-1] == 1:
score += base3
base1,base2,base3 = 1,base1,base2
elif innings[players[cu_player_ind]-1] == 2:
score += (base2+base3)
base1,base2,base3 = 0,1,base1
elif innings[players[cu_player_ind]-1] == 3:
score += (base1+base2+base3)
base1,base2,base3 = 0,0,1
else:
score = score + base1+base2+base3 + 1
base1,base2,base3 = 0,0,0
cu_player_ind = (cu_player_ind+1)%9
if score > result:
result = score
print(result)
'알고리즘 > 백준_복기_미완료' 카테고리의 다른 글
[BOJ/백준] 17404 RGB 거리 2 (0) | 2021.05.06 |
---|---|
[BOJ/백준] 17298 오큰수 (0) | 2021.05.06 |
[BOJ/백준] 17114 하이퍼 토마토 (0) | 2021.05.06 |
[BOJ/백준] 17136 색종이 붙이기 (0) | 2021.05.06 |
[BOJ/백준] 16954 움직이는 미로 탈출 (0) | 2021.05.06 |