-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombo.cpp
More file actions
76 lines (65 loc) · 1.4 KB
/
combo.cpp
File metadata and controls
76 lines (65 loc) · 1.4 KB
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
/*
ID: th3c0r11
TASK: combo
LANG: C++14
*/
#include <bits/stdc++.h>
int n;
std::array<int, 3> combo1, combo2;
int convert(int i)
{
if (i % n == 0)
return n;
return i % n;
}
int smallestDistance(int a, int b)
{
return std::min(std::abs(a - b), n - std::abs(a - b));
}
bool within(int x, int bound)
{
return smallestDistance(x, bound) <= 2;
}
bool validCombo(const std::array<int, 3> &combo)
{
bool firstNot = false;
for (int i = 0; i < 3; ++i)
if (!within(combo[i], combo1[i])) {
firstNot = true;
break;
}
if (!firstNot)
return true;
for (int i = 0; i < 3; ++i) {
if (!within(combo[i], combo2[i])) {
if (firstNot)
return false;
}
}
return true;
}
int main()
{
std::ifstream in{"combo.in"};
std::ofstream out{"combo.out"};
in >> n;
in.ignore(100, '\n');
for (auto &i : combo1)
in >> i;
in.ignore(100, '\n');
for (auto &i : combo2)
in >> i;
in.ignore(100, '\n');
int combos = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
for (int k = 1; k <= n; ++k) {
if (validCombo({i, j, k})) {
std::cout << "valid = {" << i << ", " << j << ", " << k << "}\n";
++combos;
}
}
}
}
out << combos << '\n';
}