Submission #1181904

#TimeUsernameProblemLanguageResultExecution timeMemory
1181904denizhatipogluMountains (NOI20_mountains)C++20
0 / 100
2095 ms60228 KiB
#include <iostream>
#include <future>

long long int findZ(int* H, int n, int i) {
    long long int total = 0;
    
    for (int k = i + 1; k < n; k++) {
        if (H[k] >= H[i]) continue;
        total++;
    }
    
    return total;
}

long long int findX(int* H, int n, int i) {
    std::future<long long int>* fns = new std::future<long long int>[i];
    
    for (int j = 0; j < i; j++) {
        if (H[j] >= H[i]) continue;
        fns[j] = std::async(&findZ, H, n, i);
    }
    
    long long int total = 0;
    
    for (int j = 0; j < i; j++) {
        if (H[j] >= H[i]) continue;
        total += fns[j].get();
    }
    
    
    return total;
}

int main(void) {
	int n = 0;
	
	std::cin >> n;

	int* H = new int[n];

	for (int i = 0; i < n; i++) 
		std::cin >> H[i];

	long long int total = 0;
	
	std::future<long long int>* fns = new std::future<long long int>[n - 2];
	
	for (int i = 1; i < n - 1; i++) {
		fns[i - 1] = std::async(&findX, H, n, i);
	}
	
	for (int i = 0; i < n - 2; i++) {
	    total += fns[i].get();   
	}

	std::cout << total << std::endl;

	delete H;

	return 0;
}
#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...