-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17136.cpp
87 lines (66 loc) · 1.74 KB
/
17136.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 <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
int xxxx[]={-1,0,1,0};
int yyyy[]={0,1,0,-1};
int m[10][10];
int result = 26;
int arr[5];
bool f() {
for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) if (m[i][j]) return false;
return true;
}
bool check(int x, int y, int c) {
if (!arr[c]) return false;
for (int i = 0; i <= c; i++) {
for (int j = 0; j <= c; j++) {
auto nx = x+i;
auto ny = y+j;
if (nx > 9 || ny > 9) return false;
if (!m[nx][ny]) return false;
}
}
return true;
}
int r(){
int t = 25;
for (int i = 0; i < 5; i++) t-=arr[i];
return t;
}
void dfs() {
if (f()) {
result = min(result,r());
return;
}
for (int x = 0; x < 10; x++) {
for (int y = 0; y < 10; y++) {
if (!m[x][y]) continue;
for (int c = 4; c >= 0; c--) {
if (!check(x,y,c)) continue;
arr[c]--;
for (int i = 0; i <= c; i++) for (int j = 0; j <= c; j++) m[x+i][y+j] = 0;
dfs();
arr[c]++;
for (int i = 0; i <= c; i++) for (int j = 0; j <= c; j++) m[x+i][y+j] = 1;
}
return;
}
}
}
void solve(){
for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) cin >> m[i][j];
fill(arr, arr+5, 5);
dfs();
if (result == 26) result = -1;
cout << result;
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
solve();
return 0;
}