| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1286346 | sampaio_kk | Triple Peaks (IOI25_triples) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
long long count_triples(vector<int> H) {
int N = H.size();
vector<vector<int>> pos(N);
for (int i = 0; i < N; i++) if (H[i] < N) pos[H[i]].push_back(i);
long long ans = 0;
for (int a = 1; a < N; a++) {
for (int i = 0; i + a < N; i++) {
int j = i + a;
int x = H[i], y = H[j];
vector<int> h = {x, y, a};
sort(h.begin(), h.end());
int b = h[1] - h[0];
int c = h[2] - h[1];
if (b <= 0 || c <= 0) continue;
if (h[2] != h[0] + h[1]) continue;
if (j + b < N && H[j + b] == b && H[i] == a && H[j] == h[1]) ans++;
if (j + c < N && H[j + c] == c && H[i] == a && H[j] == h[1]) ans++;
}
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
if (!(cin >> t)) return 0;
if (t == 1) {
int N;
cin >> N;
vector<int> H(N);
for (int i = 0; i < N; i++) cin >> H[i];
cout << count_triples(H) << "\n";
} else {
int M, K;
cin >> M >> K;
vector<int> H(min(M, 6));
for (int i = 0; i < (int)H.size(); i++) H[i] = i + 1;
cout << H.size() << "\n";
for (int i = 0; i < (int)H.size(); i++) cout << H[i] << " \n"[i + 1 == (int)H.size()];
}
}
