-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1624 - Chessboard and Queens.cpp
More file actions
67 lines (57 loc) · 1.35 KB
/
1624 - Chessboard and Queens.cpp
File metadata and controls
67 lines (57 loc) · 1.35 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
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define input "input.in"
#define output "output.out"
array<array<int, 8>, 8> g;
set<int> bannedx, bannedy;
set<pair<int, int>> bannedslope;
int ans = 0;
void dfs(int i) {
if (i >= 8) {
ans++;
return;
}
if (bannedx.find(i) != bannedx.end()) return;
for (int j = 0; j < 8; j++) {
if (g[i][j]) continue;
if (bannedy.find(j) != bannedy.end()) continue;
if (find_if(bannedslope.begin(), bannedslope.end(), [i, j](auto q) {
auto [qx, qy] = q;
return abs(qx - i) == abs(qy - j);
}) != bannedslope.end())
continue;
bannedy.insert(j);
bannedx.insert(i);
bannedslope.insert(make_pair(i, j));
dfs(i + 1);
bannedy.erase(j);
bannedx.erase(i);
bannedslope.erase(make_pair(i, j));
}
}
void solve() {
for (auto& i : g) {
string s;
cin >> s;
for (int j = 0; j < s.length(); j++) {
auto c = s[j];
if (c == '.')
i[j] = 0;
else
i[j] = 1;
}
}
dfs(0);
cout << ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
if (fopen(input, "r")) freopen(input, "r", stdin);
if (fopen(output, "r")) freopen(output, "w+", stdout);
int t = 1;
// cin >> t;
while (t--) solve();
}