제출 #576739

#제출 시각아이디문제언어결과실행 시간메모리
576739SlavicG카니발 티켓 (IOI20_tickets)C++17
27 / 100
544 ms70700 KiB
#include "bits/stdc++.h" #include "tickets.h" using namespace std; #define ll long long #define sz(a) (int)a.size() #define pb push_back #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define forn(i, n) for(int i=0;i < n; ++i) ll calc(vector<int> v) { sort(all(v)); int mid = v[sz(v) / 2]; ll ret = 0; forn(i, sz(v)) ret += abs(v[i] - mid); return ret; } long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); std::vector<std::vector<int>> answer(n, vector<int>(m, -1)); deque<pair<int, int>> d[n]; for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) { d[i].pb({x[i][j], j}); } sort(all(d[i])); } ll ans = 0; ll ans2 = 0; for(int kk = 0; kk < k; ++kk) { priority_queue<pair<int, int>> q; forn(i, n) q.push({d[i].front().first + d[i].back().first, i}); vector<int> v; for(int j = 0; j < n / 2; ++j) { int i = q.top().second; q.pop(); answer[i][d[i].back().second] = kk; ans += d[i].back().first; v.pb(d[i].back().first); d[i].pop_back(); } for(int j = 0; j < n / 2; ++j) { int i = q.top().second; q.pop(); answer[i][d[i].front().second] = kk; ans -= d[i].front().first; v.pb(d[i].front().first); d[i].pop_front(); } ans2 += calc(v); } assert(ans == ans2); allocate_tickets(answer); 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...