Submission #559858

#TimeUsernameProblemLanguageResultExecution timeMemory
559858AlperenTCarnival Tickets (IOI20_tickets)C++17
14 / 100
584 ms72488 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; long long find_maximum(int k, vector<vector<int>> arr) { int n = arr.size(); int m = arr[0].size(); vector ans(n, vector(m, -1)); vector zeros(n, vector<int>()), ones(n, vector<int>()); int ansvalue = 0; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ if(arr[i][j] == 0) zeros[i].push_back(j); else if(arr[i][j] == 1) ones[i].push_back(j); } } for(int i = 0; i < k; i++){ vector<pair<int, int>> v; for(int j = 0; j < n; j++) v.push_back({zeros[j].size(), j}); sort(v.begin(), v.end(), greater<decltype(v[0])>()); int zerocnt = 0, onecnt = 0; for(int j = 0; j < n / 2; j++){ if(!zeros[v[j].second].empty()){ ans[v[j].second][zeros[v[j].second].back()] = i; zeros[v[j].second].pop_back(); zerocnt++; } else{ ans[v[j].second][ones[v[j].second].back()] = i; ones[v[j].second].pop_back(); onecnt++; } } for(int j = n / 2; j < n; j++){ if(!ones[v[j].second].empty()){ ans[v[j].second][ones[v[j].second].back()] = i; ones[v[j].second].pop_back(); onecnt++; } else{ ans[v[j].second][zeros[v[j].second].back()] = i; zeros[v[j].second].pop_back(); zerocnt++; } } ansvalue += min(n / 2, onecnt) - max(onecnt - n / 2, 0); } allocate_tickets(ans); return ansvalue; }
#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...