2022, UTM, add tests + 2 solutions

This commit is contained in:
2022-06-16 21:18:18 +03:00
parent 65b15a011b
commit 5e7875aa33
82 changed files with 42357 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;
ifstream input_stream;
ofstream output_stream;
string tripletToStr(int64_t a, int64_t b, int64_t c) {
string res = to_string(a) + " " + to_string(b) + " " + to_string(c);
return res;
}
vector<string> findTriplets(vector<int64_t> nums, int N) {
vector<string> triplets;
unordered_map<string, bool> found;
int stopI = N - 2;
for (int i = 0; i < stopI; i++) {
int64_t a = nums[i];
if (a > 0) {
break;
}
int stopJ = stopI + 1; // N - 1
for (int j = i + 1; j < stopJ; j++) {
int64_t b = nums[j];
if (a + b > 0) {
break;
}
int stopK = stopJ + 1; // N
for (int k = j + 1; k < stopK; k++) {
int64_t c = nums[k];
if (a + b + c > 0) {
break;
}
if (a + b + c == 0) {
string tripletStr = tripletToStr(a, b, c);
if (found[tripletStr] == false) {
triplets.push_back(tripletStr);
}
}
}
}
}
return triplets;
}
int main() {
input_stream.open("tests/input.10");
int N;
input_stream >> N;
if (N < 3) {
cout << "NOPE" << endl;
return 0;
}
vector<int64_t> nums;
nums.reserve(N);
int64_t tmp;
for (int i = 0; i < N; i++) {
input_stream >> tmp;
nums.push_back(tmp);
}
sort(nums.begin(), nums.end());
vector<string> triplets = findTriplets(nums, N);
if (triplets.size() == 0) {
cout << "NOPE" << endl;
} else {
for (auto it = triplets.begin(); it != triplets.end(); it++) {
cout << (*it) << endl;
}
}
input_stream.close();
return 0;
}

View File

@@ -0,0 +1,2 @@
6
-2 3 4 -2 1 1

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
3
13 -5 2

View File

@@ -0,0 +1,2 @@
11
7 2 -3 1 4 -2 5 4 0 11 -4

View File

@@ -0,0 +1,2 @@
6
-5 2 0 5 3 1

View File

@@ -0,0 +1,2 @@
10
2 -2 0 2 2 -2 -2 -2 -4 4

View File

@@ -0,0 +1,2 @@
10
7 2 0 1 0 3 0 6 0 -11

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
-2 -2 4
-2 1 1

View File

@@ -0,0 +1,285 @@
-42 -42 84
-42 -38 80
-42 -36 78
-42 -34 76
-42 -31 73
-42 -30 72
-42 -26 68
-42 -25 67
-42 -23 65
-42 -18 60
-42 -16 58
-42 -11 53
-42 -8 50
-42 -3 45
-42 0 42
-42 1 41
-42 2 40
-42 4 38
-42 11 31
-42 13 29
-42 16 26
-42 19 23
-42 20 22
-42 21 21
-41 -39 80
-41 -36 77
-41 -31 72
-41 -30 71
-41 -27 68
-41 -26 67
-41 -25 66
-41 -22 63
-41 -20 61
-41 -16 57
-41 -14 55
-41 -11 52
-41 -8 49
-41 -1 42
-41 0 41
-41 1 40
-41 3 38
-41 4 37
-41 7 34
-41 12 29
-41 13 28
-41 16 25
-41 19 22
-41 20 21
-39 -39 78
-39 -38 77
-39 -34 73
-39 -27 66
-39 -26 65
-39 -22 61
-39 -18 57
-39 -16 55
-39 -14 53
-39 -11 50
-39 -8 47
-39 -3 42
-39 -1 40
-39 1 38
-39 2 37
-39 3 36
-39 11 28
-39 12 27
-39 13 26
-39 16 23
-39 19 20
-38 -38 76
-38 -34 72
-38 -30 68
-38 -27 65
-38 -25 63
-38 -23 61
-38 -22 60
-38 -20 58
-38 -16 54
-38 -14 52
-38 -11 49
-38 -8 46
-38 -3 41
-38 0 38
-38 1 37
-38 2 36
-38 4 34
-38 7 31
-38 11 27
-38 12 26
-38 13 25
-38 16 22
-38 19 19
-36 -36 72
-36 -31 67
-36 -30 66
-36 -27 63
-36 -25 61
-36 -22 58
-36 -18 54
-36 -16 52
-36 -14 50
-36 -11 47
-36 -1 37
-36 0 36
-36 2 34
-36 7 29
-36 11 25
-36 12 24
-36 13 23
-36 16 20
-34 -34 68
-34 -31 65
-34 -27 61
-34 -26 60
-34 -23 57
-34 -20 54
-34 -18 52
-34 -16 50
-34 -14 48
-34 -11 45
-34 -8 42
-34 -3 37
-34 0 34
-34 3 31
-34 7 27
-34 11 23
-34 12 22
-34 13 21
-31 -30 61
-31 -27 58
-31 -26 57
-31 -23 54
-31 -22 53
-31 -20 51
-31 -18 49
-31 -16 47
-31 -14 45
-31 -11 42
-31 -3 34
-31 0 31
-31 2 29
-31 3 28
-31 4 27
-31 7 24
-31 11 20
-31 12 19
-30 -30 60
-30 -27 57
-30 -25 55
-30 -23 53
-30 -22 52
-30 -20 50
-30 -18 48
-30 -16 46
-30 -11 41
-30 -8 38
-30 -1 31
-30 1 29
-30 2 28
-30 3 27
-30 4 26
-30 7 23
-30 11 19
-27 -27 54
-27 -26 53
-27 -25 52
-27 -23 50
-27 -22 49
-27 -20 47
-27 -18 45
-27 -14 41
-27 -11 38
-27 -1 28
-27 0 27
-27 1 26
-27 2 25
-27 3 24
-27 4 23
-27 7 20
-27 11 16
-26 -26 52
-26 -25 51
-26 -23 49
-26 -22 48
-26 -20 46
-26 -16 42
-26 -14 40
-26 -11 37
-26 -8 34
-26 -3 29
-26 -1 27
-26 0 26
-26 1 25
-26 2 24
-26 3 23
-26 4 22
-26 7 19
-26 13 13
-25 -25 50
-25 -23 48
-25 -22 47
-25 -20 45
-25 -16 41
-25 -11 36
-25 -3 28
-25 -1 26
-25 0 25
-25 1 24
-25 2 23
-25 3 22
-25 4 21
-25 12 13
-23 -23 46
-23 -22 45
-23 -18 41
-23 -14 37
-23 -11 34
-23 -8 31
-23 -3 26
-23 -1 24
-23 0 23
-23 1 22
-23 2 21
-23 3 20
-23 4 19
-23 7 16
-23 11 12
-22 -20 42
-22 -18 40
-22 -16 38
-22 -14 36
-22 -3 25
-22 -1 23
-22 0 22
-22 1 21
-22 2 20
-22 3 19
-22 11 11
-20 -20 40
-20 -18 38
-20 -16 36
-20 -14 34
-20 -11 31
-20 -8 28
-20 -3 23
-20 -1 21
-20 0 20
-20 1 19
-20 4 16
-20 7 13
-18 -18 36
-18 -16 34
-18 -11 29
-18 -8 26
-18 -3 21
-18 -1 19
-18 2 16
-18 7 11
-16 -11 27
-16 -8 24
-16 -3 19
-16 0 16
-16 3 13
-16 4 12
-14 -14 28
-14 -11 25
-14 -8 22
-14 1 13
-14 2 12
-14 3 11
-14 7 7
-11 -11 22
-11 -8 19
-11 -1 12
-11 0 11
-11 4 7
-8 -8 16
-8 -3 11
-8 1 7
-8 4 4
-3 -1 4
-3 0 3
-3 1 2
-1 -1 2
-1 0 1

View File

@@ -0,0 +1 @@
NOPE

View File

@@ -0,0 +1,5 @@
-4 -3 7
-4 0 4
-3 -2 5
-3 1 2
-2 0 2

View File

@@ -0,0 +1,2 @@
-5 0 5
-5 2 3

View File

@@ -0,0 +1,4 @@
-4 0 4
-4 2 2
-2 -2 4
-2 0 2

View File

@@ -0,0 +1 @@
0 0 0

View File

@@ -0,0 +1,75 @@
-10 -9 19
-10 -8 18
-10 -7 17
-10 -6 16
-10 -5 15
-10 -4 14
-10 -3 13
-10 -2 12
-10 -1 11
-10 0 10
-10 1 9
-10 2 8
-10 3 7
-10 4 6
-9 -8 17
-9 -7 16
-9 -6 15
-9 -5 14
-9 -4 13
-9 -3 12
-9 -2 11
-9 -1 10
-9 0 9
-9 1 8
-9 2 7
-9 3 6
-9 4 5
-8 -7 15
-8 -6 14
-8 -5 13
-8 -4 12
-8 -3 11
-8 -2 10
-8 -1 9
-8 0 8
-8 1 7
-8 2 6
-8 3 5
-7 -6 13
-7 -5 12
-7 -4 11
-7 -3 10
-7 -2 9
-7 -1 8
-7 0 7
-7 1 6
-7 2 5
-7 3 4
-6 -5 11
-6 -4 10
-6 -3 9
-6 -2 8
-6 -1 7
-6 0 6
-6 1 5
-6 2 4
-5 -4 9
-5 -3 8
-5 -2 7
-5 -1 6
-5 0 5
-5 1 4
-5 2 3
-4 -3 7
-4 -2 6
-4 -1 5
-4 0 4
-4 1 3
-3 -2 5
-3 -1 4
-3 0 3
-3 1 2
-2 -1 3
-2 0 2
-1 0 1

View File

@@ -0,0 +1,271 @@
-42 -38 80
-42 -36 78
-42 -34 76
-42 -31 73
-42 -30 72
-42 -26 68
-42 -25 67
-42 -23 65
-42 -18 60
-42 -16 58
-42 -11 53
-42 -8 50
-42 -3 45
-42 0 42
-42 1 41
-42 2 40
-42 4 38
-42 11 31
-42 13 29
-42 16 26
-42 19 23
-42 20 22
-42 21 21
-41 -39 80
-41 -36 77
-41 -31 72
-41 -30 71
-41 -27 68
-41 -26 67
-41 -25 66
-41 -22 63
-41 -20 61
-41 -16 57
-41 -14 55
-41 -11 52
-41 -8 49
-41 -1 42
-41 0 41
-41 1 40
-41 3 38
-41 4 37
-41 7 34
-41 12 29
-41 13 28
-41 16 25
-41 19 22
-41 20 21
-39 -38 77
-39 -34 73
-39 -27 66
-39 -26 65
-39 -22 61
-39 -18 57
-39 -16 55
-39 -14 53
-39 -11 50
-39 -8 47
-39 -3 42
-39 -1 40
-39 1 38
-39 2 37
-39 3 36
-39 11 28
-39 12 27
-39 13 26
-39 16 23
-39 19 20
-38 -34 72
-38 -30 68
-38 -27 65
-38 -25 63
-38 -23 61
-38 -22 60
-38 -20 58
-38 -16 54
-38 -14 52
-38 -11 49
-38 -8 46
-38 -3 41
-38 0 38
-38 1 37
-38 2 36
-38 4 34
-38 7 31
-38 11 27
-38 12 26
-38 13 25
-38 16 22
-36 -31 67
-36 -30 66
-36 -27 63
-36 -25 61
-36 -22 58
-36 -18 54
-36 -16 52
-36 -14 50
-36 -11 47
-36 -1 37
-36 0 36
-36 2 34
-36 7 29
-36 11 25
-36 12 24
-36 13 23
-36 16 20
-34 -31 65
-34 -27 61
-34 -26 60
-34 -23 57
-34 -20 54
-34 -18 52
-34 -16 50
-34 -14 48
-34 -11 45
-34 -8 42
-34 -3 37
-34 0 34
-34 3 31
-34 7 27
-34 11 23
-34 12 22
-34 13 21
-31 -30 61
-31 -27 58
-31 -26 57
-31 -23 54
-31 -22 53
-31 -20 51
-31 -18 49
-31 -16 47
-31 -14 45
-31 -11 42
-31 -3 34
-31 0 31
-31 2 29
-31 3 28
-31 4 27
-31 7 24
-31 11 20
-31 12 19
-30 -27 57
-30 -25 55
-30 -23 53
-30 -22 52
-30 -20 50
-30 -18 48
-30 -16 46
-30 -11 41
-30 -8 38
-30 -1 31
-30 1 29
-30 2 28
-30 3 27
-30 4 26
-30 7 23
-30 11 19
-27 -26 53
-27 -25 52
-27 -23 50
-27 -22 49
-27 -20 47
-27 -18 45
-27 -14 41
-27 -11 38
-27 -1 28
-27 0 27
-27 1 26
-27 2 25
-27 3 24
-27 4 23
-27 7 20
-27 11 16
-26 -25 51
-26 -23 49
-26 -22 48
-26 -20 46
-26 -16 42
-26 -14 40
-26 -11 37
-26 -8 34
-26 -3 29
-26 -1 27
-26 0 26
-26 1 25
-26 2 24
-26 3 23
-26 4 22
-26 7 19
-25 -25 50
-25 -23 48
-25 -22 47
-25 -20 45
-25 -16 41
-25 -11 36
-25 -3 28
-25 -1 26
-25 0 25
-25 1 24
-25 2 23
-25 3 22
-25 4 21
-25 12 13
-23 -23 46
-23 -22 45
-23 -18 41
-23 -14 37
-23 -11 34
-23 -8 31
-23 -3 26
-23 -1 24
-23 0 23
-23 1 22
-23 2 21
-23 3 20
-23 4 19
-23 7 16
-23 11 12
-22 -20 42
-22 -18 40
-22 -16 38
-22 -14 36
-22 -3 25
-22 -1 23
-22 0 22
-22 1 21
-22 2 20
-22 3 19
-22 11 11
-20 -20 40
-20 -18 38
-20 -16 36
-20 -14 34
-20 -11 31
-20 -8 28
-20 -3 23
-20 -1 21
-20 0 20
-20 1 19
-20 4 16
-20 7 13
-18 -16 34
-18 -11 29
-18 -8 26
-18 -3 21
-18 -1 19
-18 2 16
-18 7 11
-16 -11 27
-16 -8 24
-16 -3 19
-16 0 16
-16 3 13
-16 4 12
-14 -11 25
-14 -8 22
-14 1 13
-14 2 12
-14 3 11
-14 7 7
-11 -8 19
-11 -1 12
-11 0 11
-11 4 7
-8 -8 16
-8 -3 11
-8 1 7
-8 4 4
-3 -1 4
-3 0 3
-3 1 2
-1 0 1

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
3 2

View File

@@ -0,0 +1 @@
950 947

View File

@@ -0,0 +1 @@
4 1

View File

@@ -0,0 +1 @@
5 5

View File

@@ -0,0 +1 @@
11 7

View File

@@ -0,0 +1 @@
12 2

View File

@@ -0,0 +1 @@
13 12

View File

@@ -0,0 +1 @@
50 48

View File

@@ -0,0 +1 @@
25 19

View File

@@ -0,0 +1 @@
100 96

View File

@@ -0,0 +1 @@
3

View File

@@ -0,0 +1 @@
395645112

View File

@@ -0,0 +1 @@
6

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1 @@
157773

View File

@@ -0,0 +1 @@
120543840

View File

@@ -0,0 +1 @@
78

View File

@@ -0,0 +1 @@
730100

View File

@@ -0,0 +1 @@
908510902

View File

@@ -0,0 +1 @@
590220581

View File

@@ -0,0 +1,69 @@
#include <fstream>
#include <iostream>
using namespace std;
ifstream input_stream;
ofstream output_stream;
char numToChar(int num) {
char letter;
switch (num) {
case 15:
letter = 'F';
break;
case 14:
letter = 'E';
break;
case 13:
letter = 'D';
break;
case 12:
letter = 'C';
break;
case 11:
letter = 'B';
break;
case 10:
letter = 'A';
break;
default:
letter = '0' + num;
}
return letter;
}
string intToHex(int num) {
string res = "";
res += numToChar(num / 16);
res += numToChar(num % 16);
return res;
}
int main() {
input_stream.open("tests/input.7");
int rgb[3];
for (int i = 0; i < 3; i++) {
int tmp;
input_stream >> tmp;
if (tmp > 255) {
tmp = 255;
} else if (tmp < 0) {
tmp = 0;
}
rgb[i] = tmp;
}
cout << intToHex(rgb[0]);
cout << intToHex(rgb[1]);
cout << intToHex(rgb[2]) << endl;
return 0;
}

View File

@@ -0,0 +1 @@
255 255 255

View File

@@ -0,0 +1 @@
255 255 318

View File

@@ -0,0 +1 @@
76 20 211

View File

@@ -0,0 +1 @@
148 0 211

View File

@@ -0,0 +1 @@
0 0 0

View File

@@ -0,0 +1 @@
242 42 1

View File

@@ -0,0 +1 @@
-200 256 -1

View File

@@ -0,0 +1 @@
16 200 187

View File

@@ -0,0 +1 @@
13 33 26

View File

@@ -0,0 +1 @@
1000 899 254

View File

@@ -0,0 +1 @@
FFFFFF

View File

@@ -0,0 +1 @@
FFFFFF

View File

@@ -0,0 +1 @@
4C14D3

View File

@@ -0,0 +1 @@
9400D3

View File

@@ -0,0 +1 @@
000000

View File

@@ -0,0 +1 @@
F22A01

View File

@@ -0,0 +1 @@
00FF00

View File

@@ -0,0 +1 @@
10C8BB

View File

@@ -0,0 +1 @@
0D211A

View File

@@ -0,0 +1 @@
FFFFFE

View File

@@ -0,0 +1,2 @@
192.168.1.1
192.168.1.5

View File

@@ -0,0 +1,2 @@
10.11.12.13
10.11.13.0

View File

@@ -0,0 +1,2 @@
10.0.0.3
10.0.1.7

View File

@@ -0,0 +1,2 @@
192.166.0.0
192.168.0.0

View File

@@ -0,0 +1,2 @@
160.0.0.0
160.0.1.0

View File

@@ -0,0 +1,2 @@
50.0.0.0
50.1.1.1

View File

@@ -0,0 +1,2 @@
180.0.0.0
181.0.0.0

View File

@@ -0,0 +1,2 @@
1.2.3.4
5.6.7.8

View File

@@ -0,0 +1,2 @@
192.132.254.77
192.177.255.1

View File

@@ -0,0 +1,2 @@
0.0.0.0
255.255.255.255

View File

@@ -0,0 +1 @@
4

View File

@@ -0,0 +1 @@
243

View File

@@ -0,0 +1 @@
260

View File

@@ -0,0 +1 @@
131072

View File

@@ -0,0 +1 @@
256

View File

@@ -0,0 +1 @@
65793

View File

@@ -0,0 +1 @@
16777216

View File

@@ -0,0 +1 @@
67372036

View File

@@ -0,0 +1 @@
2949300

View File

@@ -0,0 +1 @@
4294967295