-
Notifications
You must be signed in to change notification settings - Fork 0
/
1624.cpp
73 lines (65 loc) · 1.46 KB
/
1624.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
// Problem: Chessboard and Queens
// Contest: CSES - CSES Problem Set
// URL: https://cses.fi/problemset/task/1624
// Memory Limit: 512 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(),(x).end()
#define ln cout<<'\n'
#define X first
#define Y second
#define vi vector<int>
#define vvi vector<vi>
vector<vector<bool>> used;
bool func(vector<pair<int, int>>& a){
int n = 8;
for(int i = 0; i < n; i++) {
auto [x, y] = a[i];
for(int j = 0; j < n; j++) {
if (i == j)
continue;
auto [x1, y1] = a[j];
if(used[x][y] or used[x1][y1] or abs(x1 - x) == abs(y - y1))
return false;
}
}
return true;
}
void solve()
{
used.resize(8, vector<bool>(8));
char c;
int n = 8;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
cin >> c;
used[i][j] = c == '*';
}
}
int ans = 0;
vector<int> a = {0,1,2,3,4,5,6,7};
do{
vector<pair<int, int>>x(8);
for(int i = 0; i < 8; i++) {
x[i] = {i, a[i]};
}
ans += func(x);
}while(next_permutation(a.begin(), a.end()));
cout << ans;
}
signed main()
{
fast;
int t=1;
//cin >> t;
while(t--)
{
solve();
}
return 0;
}