Task: | Alitaulukot |
Sender: | Salama |
Submission time: | 2020-10-01 18:12:55 +0300 |
Language: | C++ (C++17) |
Status: | COMPILE ERROR |
Compiler report
output/cc9TI9Fw.o: In function `std::future<std::result_of<std::decay<int (*)(int*, int, int, int, bool)>::type (std::decay<int*&>::type, std::decay<int&>::type, std::decay<double>::type, std::decay<int>::type, std::decay<bool>::type)>::type> std::async<int (*)(int*, int, int, int, bool), int*&, int&, double, int, bool>(std::launch, int (*&&)(int*, int, int, int, bool), int*&, int&, double&&, int&&, bool&&)': code.cpp:(.text._ZSt5asyncIPFiPiiiibEJRS0_RidibEESt6futureINSt9result_ofIFNSt5decayIT_E4typeEDpNS7_IT0_E4typeEEE4typeEESt6launchOS8_DpOSB_[_ZSt5asyncIPFiPiiiibEJRS0_RidibEESt6futureINSt9result_ofIFNSt5decayIT_E4typeEDpNS7_IT0_E4typeEEE4typeEESt6launchOS8_DpOSB_]+0x2c9): undefined reference to `pthread_create' output/cc9TI9Fw.o: In function `std::future<std::result_of<std::decay<int (*)(int*, int, int, int, bool)>::type (std::decay<int*&>::type, std::decay<int&>::type, std::decay<int&>::type, std::decay<double>::type, std::decay<bool>::type)>::type> std::async<int (*)(int*, int, in...
Code
#include <iostream> #include <string> #include <thread> #include <future> #include <math.h> using namespace std; int count(int list[], int biggestSub, int goal, int index, bool final) { int smallestInList, biggestInList, i; int ans = 0; while (index < goal) { i = 0; smallestInList = 1000000001; biggestInList = -1; while (true) { if (index + i == goal && final) break; if (list[index + i] < smallestInList) smallestInList = list[index + i]; if (list[index + i] > biggestInList) biggestInList = list[index + i]; if(biggestInList - smallestInList > biggestSub) break; i++; } ans += i; index++; } return ans; } int main() { int listSize, biggestSub; cin >> listSize >> biggestSub; int* list = new int[listSize]; int ans = 0; for (int i = 0; i < listSize; i++) { cin >> list[i]; } future<int> ans0 = async(launch::async, &count, list, biggestSub, round(listSize/2), 0, false); future<int> ans1 = async(launch::async, &count, list, biggestSub, listSize, round(listSize/2), true); ans += ans0.get(); ans += ans1.get(); cout << ans; }