Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7df1044

Browse files
committed
14890
1 parent 8791ee7 commit 7df1044

File tree

2 files changed

+153
-28
lines changed

2 files changed

+153
-28
lines changed

‎Baekjoon/Cpp/14890.cpp‎

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int abs(int x)
6+
{
7+
return x * (x > 0 ? 1 : -1);
8+
}
9+
10+
int main()
11+
{
12+
ios::sync_with_stdio(false);
13+
cin.tie(nullptr);
14+
cout.tie(nullptr);
15+
int n, l, i, j, k, res = 0, arr[100][100];
16+
cin >> n >> l;
17+
for (i = 0; i < n; i++)
18+
{
19+
for (j = 0; j < n; j++)
20+
{
21+
cin >> arr[i][j];
22+
}
23+
bool safe = true;
24+
int acd = 0;
25+
int front[n];
26+
int back[n];
27+
front[0] = 1;
28+
for (j = 0; j < n - 1; j++)
29+
{
30+
if (abs(arr[i][j] - arr[i][j + 1]) > 1)
31+
{
32+
safe = false;
33+
break;
34+
}
35+
front[j + 1] = 1 + front[j] * int(arr[i][j] == arr[i][j + 1]);
36+
}
37+
if (!safe)
38+
{
39+
continue;
40+
}
41+
back[n - 1] = 1;
42+
for (j = n - 1; j > 0; j--)
43+
{
44+
if (abs(arr[i][j] - arr[i][j - 1]) > 1)
45+
{
46+
safe = false;
47+
break;
48+
}
49+
back[j - 1] = 1 + back[j] * int(arr[i][j] == arr[i][j - 1]);
50+
}
51+
if (!safe)
52+
{
53+
continue;
54+
}
55+
for (j = 0; j < n - 1; j++)
56+
{
57+
if (arr[i][j] < arr[i][j + 1])
58+
{
59+
if (front[j] < l || acd < 0)
60+
{
61+
safe = false;
62+
break;
63+
}
64+
acd = 1 * l;
65+
}
66+
else if (arr[i][j] > arr[i][j + 1])
67+
{
68+
if (back[j + 1] < l)
69+
{
70+
safe = false;
71+
break;
72+
}
73+
j += l - 1;
74+
acd = -1 * l;
75+
}
76+
else if (acd != 0)
77+
{
78+
acd = acd > 0 ? acd - 1 : acd + 1;
79+
}
80+
}
81+
if (safe)
82+
{
83+
res += 1;
84+
}
85+
}
86+
for (i = 0; i < n; i++)
87+
{
88+
bool safe = true;
89+
int acd = 0;
90+
int front[n];
91+
int back[n];
92+
front[0] = 1;
93+
for (j = 0; j < n - 1; j++)
94+
{
95+
if (abs(arr[j][i] - arr[j + 1][i]) > 1)
96+
{
97+
safe = false;
98+
break;
99+
}
100+
front[j + 1] = 1 + front[j] * int(arr[j][i] == arr[j + 1][i]);
101+
}
102+
if (!safe)
103+
{
104+
continue;
105+
}
106+
back[n - 1] = 1;
107+
for (j = n - 1; j > 0; j--)
108+
{
109+
if (abs(arr[j][i] - arr[j - 1][i]) > 1)
110+
{
111+
safe = false;
112+
break;
113+
}
114+
back[j - 1] = 1 + back[j] * int(arr[j][i] == arr[j - 1][i]);
115+
}
116+
if (!safe)
117+
{
118+
continue;
119+
}
120+
for (j = 0; j < n - 1; j++)
121+
{
122+
if (arr[j][i] < arr[j + 1][i])
123+
{
124+
if (front[j] < l || acd < 0)
125+
{
126+
safe = false;
127+
break;
128+
}
129+
acd = 1 * l;
130+
}
131+
else if (arr[j][i] > arr[j + 1][i])
132+
{
133+
if (back[j + 1] < l)
134+
{
135+
safe = false;
136+
break;
137+
}
138+
j += l - 1;
139+
acd = -1 * l;
140+
}
141+
else if (acd != 0)
142+
{
143+
acd = acd > 0 ? acd - 1 : acd + 1;
144+
}
145+
}
146+
if (safe)
147+
{
148+
res += 1;
149+
}
150+
}
151+
cout << res;
152+
return 0;
153+
}

‎Baekjoon/Cpp/2512.cpp‎

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,3 @@ int main()
8080
cout << res;
8181
return 0;
8282
}
83-
84-
// n = 4
85-
// arr = 110 120 140 150
86-
// acr = 110 230 370 520
87-
// m = 485
88-
89-
// start = 0
90-
// end = 3
91-
92-
// cur = 2
93-
// m - acr[cur - 1] = 255
94-
// arr[cur] = 140
95-
// 140 * (n - cur) = 280
96-
97-
// end = 1
98-
// cur = 1
99-
100-
// arr[cur] = 120
101-
// m - acr[cur - 1] = 375
102-
// 120 * (n - cur) = 360
103-
104-
// start = 2
105-
// end = 1
106-
107-
// m = 375
108-
// 121 * 3 = 363
109-
// 122 * 3 = 366
110-
// 127 * 3 = 381

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /