Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
85 lines (77 loc) · 2.2 KB
/
Copy pathmain.cpp
File metadata and controls
85 lines (77 loc) · 2.2 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
// Authored by : tony9402
// Co-authored by : -
// Link : http://boj.kr/4e60b2336bfa4e3192b9aef4eb5a3f6b
#include<bits/stdc++.h>
using namespace std;
const int dy[] = {-1,1,0,0};
const int dx[] = {0,0,-1,1};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int K, Q; cin >> K >> Q;
int N = 1 << K;
vector<vector<int>> Map(N, vector<int>(N));
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
cin >> Map[i][j];
}
}
while(Q--) {
int L; cin >> L;
int M = 1 << L;
vector<vector<int>> tmp = Map;
for(int i=0;i<N;i+=M){
for(int j=0;j<N;j+=M){
for(int m=0;m<M;m++){
for(int n=0;n<M;n++){
Map[i+n][j+M-1-m] = tmp[i+m][j+n];
}
}
}
}
tmp = Map;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
if(Map[i][j] == 0)continue;
int cnt = 0;
for(int k=0;k<4;k++) {
int qy = i + dy[k];
int qx = j + dx[k];
if(0 > qy || qy >= N || 0 > qx || qx >= N) continue;
if(Map[qy][qx] != 0) cnt ++;
}
if(cnt < 3) tmp[i][j] --;
}
}
Map = tmp;
}
int total = 0;
int mx = 0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
if(Map[i][j] == 0)continue;
total += Map[i][j];
int cnt = 0;
Map[i][j] = 0;
queue<pair<int, int>> q;
q.emplace(i, j);
while(!q.empty()) {
auto [y, x] = q.front(); q.pop();
cnt++;
for(int k=0;k<4;k++){
int qy = y + dy[k];
int qx = x + dx[k];
if(0 > qy || qy >= N || 0 > qx || qx >= N) continue;
if(Map[qy][qx] == 0)continue;
q.emplace(qy, qx);
total += Map[qy][qx];
Map[qy][qx] = 0;
}
}
mx = max(mx, cnt);
}
}
cout << total << '\n';
cout << mx;
return 0;
}