1+ #include < iostream>
2+ #include < vector>
3+ #include < queue>
4+
5+ using namespace std ;
6+ vector<vector<int >> dices;
7+
8+ int findingM (int dindex, int underIndex) {
9+ priority_queue<int > atleast2;
10+
11+ if (underIndex == 0 || underIndex == 5 ) {
12+ for (int j = 0 ; j < 6 ; j++) {
13+ if (j != 0 && j != 5 )
14+ atleast2.push (dices[dindex][j]);
15+ }
16+ }
17+ else if (underIndex == 1 || underIndex == 3 ) {
18+ for (int j = 0 ; j < 6 ; j++) {
19+ if (j != 1 && j != 3 )
20+ atleast2.push (dices[dindex][j]);
21+ }
22+
23+ }
24+ else if (underIndex == 2 || underIndex == 4 ) {
25+ for (int j = 0 ; j < 6 ; j++) {
26+ if (j != 2 && j != 4 )
27+ atleast2.push (dices[dindex][j]);
28+ }
29+ }
30+
31+
32+
33+ return atleast2.top ();
34+ }
35+
36+
37+
38+ int main () {
39+ freopen_s (new FILE *, " input.txt" , " r" , stdin);
40+ ios::sync_with_stdio (false );
41+ cin.tie (nullptr );
42+ int cnt;
43+ cin >> cnt;
44+ dices.assign (cnt, vector<int >(6 ,0 ));
45+
46+ for (int i = 0 ; i < cnt; i++) {
47+ for (int j = 0 ; j < 6 ; j++) {
48+ cin >> dices[i][j];
49+ }
50+ }
51+
52+
53+
54+ priority_queue<int > asf;
55+
56+ for (int i = 0 ; i < 6 ; i++) {
57+ priority_queue<int > atleast;
58+
59+ if (i == 0 || i == 5 ) {
60+ for (int j = 0 ; j < 6 ; j++) {
61+ if (j != 0 && j != 5 )
62+ atleast.push (dices[0 ][j]);
63+ }
64+ }
65+ else if (i == 1 || i == 3 ) {
66+ for (int j = 0 ; j < 6 ; j++) {
67+ if (j != 1 && j != 3 )
68+ atleast.push (dices[0 ][j]);
69+ }
70+
71+ }
72+ else if (i == 2 || i == 4 ) {
73+ for (int j = 0 ; j < 6 ; j++) {
74+ if (j != 2 && j != 4 )
75+ atleast.push (dices[0 ][j]);
76+ }
77+ }
78+
79+ int mmmax = atleast.top (), temp=0 ;
80+ int nextUnder = dices[0 ][i]; // 1번의 맨 위 숫자, 현재의 top, 다음의 under
81+
82+ for (int l = 0 ; l < 4 ; l++)
83+ {
84+ atleast.pop ();
85+ }
86+
87+
88+
89+ for (int k = 1 ; k < cnt; k++) {
90+ for (int j = 0 ; j < 6 ; j++) {
91+ if (dices[k][j] == nextUnder) {
92+ temp = findingM (k, j);
93+
94+ if (k == cnt-1 ) continue ;
95+ if (j == 0 ) nextUnder = dices[k][5 ];
96+ else if (j == 1 ) nextUnder = dices[k][3 ];
97+ else if (j == 2 ) nextUnder = dices[k][4 ];
98+ else if (j == 3 ) nextUnder = dices[k][1 ];
99+ else if (j == 4 ) nextUnder = dices[k][2 ];
100+ else if (j == 5 ) nextUnder = dices[k][0 ];
101+
102+ break ;
103+ }
104+ }
105+ mmmax += temp;
106+ }
107+
108+ asf.push (mmmax);
109+ }
110+
111+
112+ cout << asf.top ();
113+
114+ return 0 ;
115+ }
0 commit comments