-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02b-red-nosed-reports.cpp
More file actions
48 lines (44 loc) · 878 Bytes
/
02b-red-nosed-reports.cpp
File metadata and controls
48 lines (44 loc) · 878 Bytes
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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef _DEBUG
#include "utils/debug.h"
#else
#define debug(...)
#endif
int main() {
cin.tie(0)->sync_with_stdio(0);
string line;
ll ans = 0;
auto safe = [&](vector<int> v) -> bool {
vector<int> f = v;
vector<int> r = v;
sort(f.begin(), f.end());
sort(r.begin(), r.end(), greater<int>());
if (v != f && v != r) return 0;
bool ok = 1;
for (int i = 1; i < (int)v.size(); ++i) {
ok &= abs(v[i] - v[i-1]) <= 3 && abs(v[i] - v[i-1]) > 0;
}
return ok;
};
while (getline(cin, line)) {
istringstream iss(line);
vector<int> v;
int x;
while (iss >> x) v.push_back(x);
if (safe(v)) {
ans++;
continue;
}
for (int i = 0; i < (int)v.size(); ++i) {
auto cur = v;
cur.erase(cur.begin() + i);
if (safe(cur)) {
ans++;
break;
}
}
}
cout << ans << '\n';
}