제출 #823167

#제출 시각아이디문제언어결과실행 시간메모리
823167fatemetmhr카니발 티켓 (IOI20_tickets)C++17
100 / 100
1669 ms109968 KiB
// :)^2 #include "tickets.h" #include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define fi first #define se second #define mp make_pair #define pb push_back typedef long long ll; const int maxn5 = 2e3 + 10; pair <ll, int> per[maxn5]; int ptl[maxn5], ptr[maxn5], val[maxn5][maxn5], cnt[maxn5]; vector <int> req[maxn5][2], ind[maxn5]; vector <pair<int, pair<int, int>>> av; priority_queue <pair<ll, int>> mx; 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>> ret; for (int i = 0; i < n; i++) { ptl[i] = k - 1; ptr[i] = m - 1; mx.push({x[i][k - 1] + x[i][m - 1], i}); vector <int> row(m); fill(all(row), -1); ret.push_back(row); } int tt = k * (n / 2); while(tt--){ int v = mx.top().se; mx.pop(); ptl[v]--; ptr[v]--; if(ptl[v] >= 0) mx.push({x[v][ptl[v]] + x[v][ptr[v]], v}); } for(int i = 0; i < n; i++){ for(int j = 0; j <= ptl[i]; j++) av.pb({x[i][j], {i, j}}); for(int j = ptr[i] + 1; j < m; j++) av.pb({x[i][j], {i, j}}); } sort(all(av)); for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) if(j <= ptl[i] || j > ptr[i]){ int pt = lower_bound(all(av), mp(x[i][j], mp(i, j))) - av.begin(); ind[i].pb(j); if(pt < int(av.size()) / 2){ val[i][j] = 0; } else{ val[i][j] = 1; } cnt[i] += val[i][j]; } for(int i = 0; i < n; i++){ ptl[i] = 0; ptr[i] = int(ind[i].size()) - 1; } ll ans = 0; int num = 0; while(k--){ for(int i = 0; i < n; i++) per[i] = {cnt[i], i}; sort(per, per + n); for(int i = 0; i < n / 2; i++){ int v = per[i].se; ans -= x[v][ind[v][ptl[v]]]; //cout << "small " << v << ' ' << cnt[v] << ' ' << num << ' ' << ptl[v] << ' ' << x[v][ptl[v]] << ' ' << ans << endl; ret[v][ind[v][ptl[v]]] = num; cnt[v] -= val[v][ind[v][ptl[v]]]; ptl[v]++; } for(int i = n / 2; i < n; i++){ int v = per[i].se; ans += x[v][ind[v][ptr[v]]]; //cout << "big " << v << ' ' << cnt[v] << ' ' << num << ' ' << ptr[v] << ' ' << x[v][ptr[v]] << ' ' << ans << endl; ret[v][ind[v][ptr[v]]] = num; cnt[v] -= val[v][ind[v][ptr[v]]]; ptr[v]--; } num++; } allocate_tickets(ret); 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...