Submission #319279

#TimeUsernameProblemLanguageResultExecution timeMemory
319279northlakeCarnival Tickets (IOI20_tickets)C++17
0 / 100
1 ms384 KiB
#include<bits/stdc++.h> #include<tickets.h> using namespace std; long long find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vector<int>> s {x}; for (auto& e1 : s) { for (auto& e2 : e1) e2 = -1; } vector<pair<int,int>> min_values; vector<pair<int,int>> max_values; for (int i = 0; i < n; i++) { vector<int> el = x[i]; int minx = pow(10,9); int maxx = 0; for (auto e : el) { minx = min(minx, e); maxx = max(maxx, e); } min_values.push_back(make_pair(minx, i)); max_values.push_back(make_pair(maxx, i)); } sort(min_values.begin(), min_values.end()); sort(max_values.rbegin(), max_values.rend()); vector<int> values; bool taken[n] = {false}; for (int i = 0; i < n; i++) { pair<int,int> small = min_values[i]; pair<int,int> big = max_values[i]; if (taken[small.second] && taken[big.second]) { continue; } else if (taken[small.second]) { values.push_back(big.first); taken[big.second] = true; } else if (taken[big.second]) { values.push_back(small.first); taken[small.second] = true; } else if (small.second == big.second) { values.push_back(small.first); taken[small.second] = true; } else { values.push_back(small.first); values.push_back(big.first); taken[big.second] = true; taken[small.second] = true; } } sort(values.begin(), values.end()); for (auto val : values) cout << val << " "; cout << '\n'; int optimal_value = values[n/2]; long long result = 0ll; for (auto el : x) { result += static_cast<long long>(abs(optimal_value-el[0])); } allocate_tickets(s); return result; }

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:8:9: warning: unused variable 'm' [-Wunused-variable]
    8 |     int m = x[0].size();
      |         ^
#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...