Submission #607498

#TimeUsernameProblemLanguageResultExecution timeMemory
607498Jarif_RahmanCarnival Tickets (IOI20_tickets)C++17
25 / 100
992 ms84396 KiB
#include "tickets.h" #include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; ll find_maximum(int K, vector<vector<int>> v){ int n = v.size(), m = v[0].size(); vector<vector<int>> pos(n, vector<int>(m, -1)); vector<pair<int, int>> sth; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) sth.pb({i, j}); sort(sth.begin(), sth.end(), [&](pair<int, int> a, pair<int, int> b){ if(v[a.f][a.sc] == v[b.f][b.sc]) return make_pair(a.sc, a.f) > make_pair(b.sc, b.f); return v[a.f][a.sc] > v[b.f][b.sc]; }); ll ans = 0; vector<int> cnt(n), o(n); vector<vector<bool>> plus(n, vector<bool>(m, 0)); for(int i = 0; i < (n*m)/2; i++) cnt[sth[i].f]++, plus[sth[i].f][sth[i].sc] = 1; for(int i = 0; i < n; i++) o[i] = i; vector<int> L(n, 0), R(n, m-1); for(int k = 0; k < K; k++){ sort(o.begin(), o.end(), [&cnt](int a, int b){ return cnt[a] < cnt[b]; }); for(int j = 0, i = o[0]; j < n/2; j++, i = o[j]){ pos[i][L[i]] = k; if(plus[i][L[i]]) cnt[i]--; ans-=v[i][L[i]]; L[i]++; } for(int j = n/2, i = o[n/2]; j < n; j++, i = o[j]){ pos[i][R[i]] = k; if(plus[i][R[i]]) cnt[i]--; ans+=v[i][R[i]]; R[i]--; } } allocate_tickets(pos); return ans; }
#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...