-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
39 lines (30 loc) · 808 Bytes
/
main.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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline void solve() {
vector<string> board(8);
for (int i = 0; i < 8; ++i) cin >> board[i];
int result = 0;
vector<bool> col(8), diag0(15), diag1(15);
function<void(int)> dfs = [&](int i) -> void {
if (i == 8) {
++result;
return;
}
for (int j = 0; j < 8; ++j) {
if (board[i][j] == '*') continue;
if (col[j] || diag0[i + j] || diag1[i - j + 7]) continue;
col[j] = diag0[i + j] = diag1[i - j + 7] = true;
dfs(i + 1);
col[j] = diag0[i + j] = diag1[i - j + 7] = false;
}
};
dfs(0);
cout << result;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}