summaryrefslogtreecommitdiff
path: root/2024/2A.cpp
blob: be4594cad75e9191761ab2bedd860925cee4b4b2 (plain)
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
#include <bits/stdc++.h>
#include "readfile.hpp"


int main(int argc, char const *argv[])
{
	int res = 0;
	std::vector<std::string> file = readfile("2.in");
	if (file.empty())
		return 1;

	for (const auto &line : file) {
		std::istringstream iss(line);
		int n;
		bool safe = true;
		int prev = -1;
		bool increasing = false, decreasing = false;
		// put to vector and pair of two
		while (iss >> n) {
			if (prev == -1) {
				prev = n;
				continue;
			}
			if (prev < n)
				increasing = true;
			else if (prev > n)
				decreasing = true;
			// all conditions for unsafe lol
			if (std::abs(prev - n) > 3 || prev == n || (n > prev && decreasing || n < prev && increasing || increasing && decreasing || !increasing && !decreasing)) {
				safe = false;
				break;
			}
			prev = n;
		}
		if (safe) {
			res++;
		}
	}

	// print
	std::cout << res << std::endl;
}