문제
https://www.acmicpc.net/problem/14890
해설
경우의 수만 잘 나누면 어렵지 않았던 문제
가로 세로 로직을 따로 구현하는 것이 아닌 map1[i][j] = map2[j][i]를 이용하여 하나의 로직으로 가로 세로 모두 확인
코드
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
|
#include <iostream>
#include <algorithm>
using namespace std;
int n, l, mp[104][104], mp2[104][104], ret;
void go(int num, int a[104][104])
{
int now_num = a[num][0];
int flag = 0;
int cnt = 1;
for (int i = 1; i < n; i++)
{
if (now_num == a[num][i])
cnt++;
else if (abs(now_num - a[num][i]) >= 2)
{
return;
}
else if (now_num < a[num][i])
{
if (cnt >= l && flag == 0)
{
cnt = 1;
now_num = a[num][i];
}
else
{
return;
}
}
else if (now_num > a[num][i])
{
if (flag == 0)
{
flag = 1;
now_num = a[num][i];
cnt = 1;
}
else
{
return;
}
}
if (flag == 1 && cnt == l)
{
flag = 0;
cnt = 0;
}
}
if (flag == 0)
ret++;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> l;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cin >> mp[i][j];
mp2[j][i] = mp[i][j];
}
}
for (int i = 0; i < n; i++)
{
go(i, mp);
go(i, mp2);
}
cout << ret;
}
|
cs |
'백준 알고리즘(C++)' 카테고리의 다른 글
백준 1094번 막대기 ( C++ ) (0) | 2024.08.29 |
---|---|
백준 1062번 가르침 ( C++ ) (0) | 2024.08.29 |
백준 17471번 케리맨더링 ( C++ ) (0) | 2024.08.26 |
백준 1285번 동전 뒤집기( C++ ) (0) | 2024.08.25 |
백준 19942번 다이어트 ( C++ ) (0) | 2024.08.25 |