-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1624.cpp
More file actions
62 lines (58 loc) · 1.25 KB
/
1624.cpp
File metadata and controls
62 lines (58 loc) · 1.25 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
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll int64_t
#define ull uint64_t
#define MOD1 998244353
#define MOD2 1000000007
using namespace std;
bool safe(vector<vector<int>>& board, int row, int col){
if(board[row][col] == -1)
return false;
for(int i = 0;i < col;i += 1)
if(board[row][i] == 1)
return false;
for(int i = row, j = col;i >= 0 && j >= 0;i --,j --)
if(board[i][j] == 1)
return false;
for(int i = row, j = col;j >= 0 && i < board.size();i ++,j --)
if(board[i][j] == 1)
return false;
return true;
}
bool solveNQUtil(vector<vector<int>>& board, int col, int& count){
if(col == board.size()){
count += 1;
return true;
}
bool res = false;
for(int i = 0;i < board.size();i += 1){
if(safe(board, i, col)){
board[i][col] = 1;
res = solveNQUtil(board, col + 1, count) || res;
board[i][col] = 0;
}
}
return res;
}
void solveNQ(vector<vector<int>>& board){
int count = 0;
if(!solveNQUtil(board, 0, count)){
cout << 0;
}
cout << count;
}
int main() {
IOS;
char c;
vector<vector<int>> board(8, vector<int>(8, 0));
for(int i = 0;i < 8;i += 1){
for(int j = 0;j < 8;j += 1){
cin >> c;
if(c == '*')
board[i][j] = -1;
}
}
solveNQ(board);
return 0;
}