Posts 14890 Samsung sw test
Post
Cancel

14890 Samsung sw test

14890 Samsung sw test

코드

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 <cstring>
#define MAX_N 100

using namespace std;

int map[MAX_N][MAX_N];
int width;
int need;

int checkEveryArr();
bool checkSingleArr(int arr[MAX_N]);

int main() {
	cin >> width >> need;
	for (int i = 0; i < width; i++)
		for (int j = 0; j < width; j++)
			cin >> map[i][j];
	cout << checkEveryArr();
}

int checkEveryArr() {
	int count = 0;

	//행
	int temp[MAX_N];
	for (int row = 0; row < width; row++) {
		if (checkSingleArr(map[row])) {
			count++;
		}
	}

	//열
	for (int col = 0; col < width; col++) {
		for (int j = 0; j < width; j++)
			temp[j] = map[j][col];
		if (checkSingleArr(temp)) {
			count++;
		}
	}
	return count;
}

bool checkSingleArr(int arr[MAX_N]) {
	bool checked[MAX_N];
	memset(checked, 0, sizeof(bool) * width);

	int ex = arr[0];
	for (int i = 1; i < width; i++) {
		if (ex != arr[i]) {
			int difference = ex - arr[i];
			if (difference == -2 || difference == 2)
				return false;

			if (difference == 1) {
				if (width - i >= need) {
					for (int k = 0; k < need; k++)
						if (arr[i] != arr[i + k])
							return false;
					for (int k = 0; k < need; k++)
						checked[i + k] = true;
				}
				else
					return false;
			}
			else if (difference == -1) {
				if (i >= need) {
					for (int k = 1; k <= need; k++)
						if (ex != arr[i - k] || checked[i-k])
							return false;
				}
				else
					return false;
			}
		}
		ex = arr[i];
	}
	return true;
}
This post is licensed under CC BY 4.0 by the author.

14889 Samsung sw test

14891 Samsung sw test

Comments powered by Disqus.