Submission #1252324

#TimeUsernameProblemLanguageResultExecution timeMemory
1252324walrusramen21Triple Peaks (IOI25_triples)C++20
14.17 / 100
189 ms1972 KiB
#include "triples.h"
#include <algorithm>
#include <array>
#include <iterator>

long long count_triples(std::vector<int> H) {
	int N = H.size();
	long long ans = 0;
	// wow I love murdering subtasks
	if (N <= 100) {
		for (int i = 0; i < N; i++) {
			for (int j = i+1; j < N; j++) {
				for (int k = j+1; k < N; k++) {
					std::array<int, 3> a = {j-i, k-i, k-j};
					std::array<int, 3> b = {H[i], H[j], H[k]};
					std::sort(a.begin(), a.end());
					std::sort(b.begin(), b.end());
					if (a[0]==b[0] && a[1]==b[1] && a[2]==b[2]) ++ans;
				}
			}
		}
	} else {
		// let's assume all elements are at most 10
		// we know j-i = x, k-j = y, k-i = (x+y)
		// since all elements are most 10, there's only oh so many values of x and y
		for (int i = 1; i < 10; i++) {
			for (int j = 1; j < 11-i; j++) {
				int limit = N-(i+j);
				for (int v = 0; v < limit; v++) {
					int x = H[v], y = H[v+i], z = H[v+i+j];
					std::array<int, 3> a = {x, y, z};
					std::array<int, 3> b = {i, j, i+j};
					std::sort(a.begin(), a.end());
					std::sort(b.begin(), b.end());
					if (a[0]==b[0] && a[1]==b[1] && a[2]==b[2]) ans++;
				}
			}
		}
	}
	return ans;
}

std::vector<int> construct_range(int M, int K) {
	return {1, 1, 2};
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...