-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14_ctScan.cpp
More file actions
72 lines (65 loc) · 1.55 KB
/
14_ctScan.cpp
File metadata and controls
72 lines (65 loc) · 1.55 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
68
69
70
71
72
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> row, col, diagR, diagL; // 입력
vector<int> r(10), c(10), dR(19), dL(19); // 현재 상태
vector<vector<bool>> grid;
void input(vector<int> &v, int n)
{
v.resize(n);
for (int &x : v)
cin >> x;
}
void dfs(int idx)
{
if (idx == n * n)
{
for (int i = 0; i < 2 * n - 1; i++)
if (dR[i] != diagR[i] || dL[i] != diagL[i])
return;
for (auto &c : grid)
{
for (bool e : c)
{
cout << (e ? "B " : "- ");
}
cout << '\n';
}
exit(0);
}
int i = idx / n, j = idx % n, dl = i + j, dr = i - j + n - 1;
for (int v = 0; v < 2; v++)
{
int tempR = r[i], tempC = c[j], tempDR = dR[dr], tempDL = dL[dl];
if (v)
{
r[i]++;
c[j]++;
dR[dr]++;
dL[dl]++;
}
bool check = r[i] <= row[i] && c[j] <= col[j] &&
dR[dr] <= diagR[dr] && dL[dl] <= diagL[dl] &&
(j < n - 1 || r[i] == row[i]) && (i < n - 1 || c[j] == col[j]);
if (check)
{
grid[i][j] = v;
dfs(idx + 1);
}
r[i] = tempR;
c[j] = tempC;
dR[dr] = tempDR;
dL[dl] = tempDL;
}
}
int main()
{
// ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
input(col, n);
input(row, n);
input(diagR, 2 * n - 1);
input(diagL, 2 * n - 1);
grid.resize(n, vector<bool>(n, 0));
dfs(0);
}