제출 #576756

#제출 시각아이디문제언어결과실행 시간메모리
576756SlavicG카니발 티켓 (IOI20_tickets)C++17
27 / 100
3072 ms79820 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, ans2 = 0; vector<array<int, 3>> amogus; for(int kk = 0; kk < k; ++kk) { priority_queue<pair<int, int>> q; forn(i, n) sort(all(d[i])); 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(); amogus.pb({d[i].back().first, i, d[i].back().second}); d[i].pop_back(); } for(int j = 0; j < n / 2; ++j) { int i = q.top().second; q.pop(); amogus.pb({d[i].front().first, i, d[i].front().second}); d[i].pop_front(); } } sort(all(amogus)); vector<vector<int>> t(n, vector<int>(m, 0)); forn(i, sz(amogus)) { t[amogus[i][1]][amogus[i][2]] = 1; ans += amogus[i][0]; } for(int i = 0; i < sz(amogus) / 2; ++i) { t[amogus[i][1]][amogus[i][2]] = 2; ans -= 2 * amogus[i][0]; } vector<int> small[n], big[n]; for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) { if(t[i][j] == 1) big[i].pb(j); else if(t[i][j] == 2) small[i].pb(j); } } priority_queue<pair<int, int>> q; forn(i, n) { if(sz(big[i])) q.push({sz(big[i]), i}); } for(int kk = 0; kk < k; ++kk) { vector<bool> vis(n, false); assert(sz(q) >= n / 2); for(int f = 0; f < n / 2; ++f) { int i = q.top().second; vis[i] = true; q.pop(); answer[i][big[i].back()] = kk; big[i].pop_back(); } for(int i = 0; i < n; ++i) { if(!vis[i]) { assert(sz(small[i])); answer[i][small[i].back()] = kk; small[i].pop_back(); } } while(!q.empty()) q.pop(); forn(i, n) { if(sz(big[i])) q.push({sz(big[i]), i}); } } allocate_tickets(answer); return ans; }

컴파일 시 표준 에러 (stderr) 메시지

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:31:17: warning: unused variable 'ans2' [-Wunused-variable]
   31 |     ll ans = 0, ans2 = 0;
      |                 ^~~~
#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...