-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSW expert-활주로 건설.cpp.txt
132 lines (114 loc) · 1.83 KB
/
SW expert-활주로 건설.cpp.txt
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include<queue>
#include<map>
using namespace std;
int N, X;
bool check_possible(vector<int> v,int x,int y)
{
bool is_K[21];
for (int i = 0; i < N; i++)
is_K[i] = true;
int num = v[0];
for (int i = 1; i < N; i++)
{
if (v[i] - num >= 1)
{
if (v[i] - num > 1)
return false;
if (i - X < 0)
return false;
bool check_s = true;
for (int s = 1; s <= X; s++)
{
if ((v[i - s] + 1) == v[i] && is_K[i - s])
{
;
}
else
check_s = false;
}
if (check_s)
{
for (int s = 1; s <= X; s++)
{
is_K[i - s] = false;
}
num = v[i];
}
else
return false;
}
else if (v[i] - num <= -1)
{
if (v[i] - num < -1)
return false;
if (i + X > N)
return false;
bool check_s = true;
for (int s = 0; s < X; s++)
{
if ((v[i + s] + 1) == v[i-1] && is_K[i + s])
{
;
}
else
check_s = false;
}
if (check_s)
{
for (int s = 0; s < X; s++)
{
is_K[i + s] = false;
}
num = v[i];
}
else
return false;
}
}
return true;
}
int main()
{
int testcase,countT;
cin >> testcase;
countT = 1;
while (testcase != 0)
{
int map_s[21][21];
cin >> N >> X;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
cin >> map_s[i][j];
}
int ret = 0;
for (int i = 0; i < N; i++)
{
vector<int> check_v;
for (int j = 0; j < N; j++)
{
check_v.push_back(map_s[i][j]);
}
if (check_possible(check_v,i,-1))
ret++;
}
for (int j = 0; j < N; j++)
{
vector<int> check_v;
for (int i = 0; i < N; i++)
{
check_v.push_back(map_s[i][j]);
}
if (check_possible(check_v,-1,j))
ret++;
}
cout << "#"<<countT++<<" "<<ret << endl;
testcase--;
}
return 0;
}