-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17281.cpp
87 lines (82 loc) · 1.51 KB
/
17281.cpp
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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<vector<int>> v;
vector<int> base;
int moveBase(int num)
{
int inning_score = 0;
// 3루부터 주자 이동
for (int i = 2; i >= 0; i--)
{
if (base[i] == 1)
{
if (i + num >= 3)
inning_score++;
else
base[i + num] = 1;
base[i] = 0;
}
}
// 타자 본인
base[num - 1] = 1;
return inning_score;
}
int game(vector<int> order, int n)
{
order.insert(order.begin() + 3, 0);
int game_score = 0, cnt, player = 0;
for(int i=0; i<n; i++)
{
cnt = 0;
base = vector<int>(3, 0);
while (cnt < 3)
{
switch (v[i][order[(player++)%9]])
{
case 0:
cnt++;
break;
case 1:
game_score += moveBase(1);
break;
case 2:
game_score += moveBase(2);
break;
case 3:
game_score += moveBase(3);
break;
case 4:
game_score += 1 + base[0] + base[1] + base[2];
base[0] = 0;
base[1] = 0;
base[2] = 0;
break;
}
}
}
return game_score;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
// 입력
int n;
cin >> n;
v = vector<vector<int>>(n, vector<int>(9, 0));
for (int i = 0; i < n; i++)
for (int j = 0; j < 9; j++)
cin >> v[i][j];
int score = 0;
vector<int> order;
for (int i = 1; i <= 8; i++)
order.push_back(i);
// 연산
while (next_permutation(order.begin(), order.end()))
score = max(score, game(order, n));
// 출력
cout << score << '\n';
return 0;
}