-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_12100.cpp
More file actions
99 lines (89 loc) · 2.05 KB
/
BOJ_12100.cpp
File metadata and controls
99 lines (89 loc) · 2.05 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// 21/11/24
#include <iostream>
#include <vector>
using namespace std;
int n;
int answer = 0;
vector<vector<int>> pushBlock(vector<vector<int>> matrix)
{
vector<vector<int>> output(n, vector<int>(n, 0));
for (int i = 0; i < n; i++)
{
vector<int> arr;
bool check = true;
for (int j = 0; j < n; j++)
{
if (matrix[i][j])
{
if (check)
{
arr.push_back(matrix[i][j]);
check = false;
}
else
{
if (arr.back() == matrix[i][j])
{
arr.back() *= 2;
check = true;
}
else
arr.push_back(matrix[i][j]);
}
}
}
for (int j = 0; j < (int)arr.size(); j++)
output[i][j] = arr[j];
}
return output;
}
vector<vector<int>> curl(vector<vector<int>> &matrix)
{
vector<vector<int>> output(n, vector<int>(n, 0));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
output[n - j - 1][i] = matrix[i][j];
}
}
return output;
}
void DFS(vector<vector<int>> matrix, int level)
{
if (level == 5)
{
int nowAnswer = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (matrix[i][j] > nowAnswer)
nowAnswer = matrix[i][j];
}
}
if (nowAnswer > answer)
answer = nowAnswer;
return;
}
for (int i = 0; i < 4; i++)
{
DFS(pushBlock(matrix), level + 1);
matrix = curl(matrix);
}
}
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
vector<vector<int>> matrix(n, vector<int>(n, 0));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
cin >> matrix[i][j];
}
DFS(matrix, 0);
cout << answer;
return 0;
}