#include "triples.h"
#include <vector>
#include <algorithm>
using namespace std;
tuple<int, int, int> sort3(int a, int b, int c) {
if (a > b) swap(a, b);
if (b > c) swap(b, c);
if (a > b) swap(a, b);
return {a, b, c};
}
long long count_triples(vector<int> H) {
int n = H.size();
long long res = 0;
if (n <= 2000) {
for (int i = 0; i < n; ++i)
for (int k = i + 2; k < n; ++k)
if ((i + k) % 2 == 0) {
int j = (i + k) / 2;
auto [h1, h2, h3] = sort3(H[i], H[j], H[k]);
int d1 = j - i, d2 = k - i, d3 = k - j;
auto [x1, x2, x3] = sort3(d1, d2, d3);
if (h1 == x1 && h2 == x2 && h3 == x3)
res++;
}
return res;
}
bool small_value = true;
for (int h : H)
if (h > 10) {
small_value = false;
break;
}
if (small_value) {
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < min(n, i + 11); ++j)
for (int k = j + 1; k < min(n, i + 22); ++k) {
auto [h1, h2, h3] = sort3(H[i], H[j], H[k]);
int d1 = j - i, d2 = k - i, d3 = k - j;
auto [x1, x2, x3] = sort3(d1, d2, d3);
if (h1 == x1 && h2 == x2 && h3 == x3)
res++;
}
return res;
}
return 0;
}
vector<int> construct_range(int M, int K) {
return {1, 1, 2};
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |