Submission #753721

#TimeUsernameProblemLanguageResultExecution timeMemory
753721nicksmsCarnival Tickets (IOI20_tickets)C++17
100 / 100
649 ms76216 KiB
/** * Author: Nicholas Winschel * Created: 05.10.2023 02:23:53 **/ #include <bits/stdc++.h> using namespace std; using ll=long long; using db=long double; template<class T> using V=vector<T>; using vi = V<int>; using vl = V<ll>; using pi = pair<int,int>; #define f first #define s second #define sz(x) (int)((x).size()) long long find_maximum(int k, std::vector<std::vector<int>> d); void allocate_tickets( std::vector<std::vector<int>> _x); 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>> ans(n, vi(m,-1)); ll cnt = 0; vi p(n); priority_queue<pi> h; for (int i = 0; i < n; i++) { h.emplace(x[i][m-1]+x[i][k-1],i); for (int j = 0; j < k; j++) cnt -= x[i][j]; } for (int _ = 0; _ < k*n/2; _++) { int i = h.top().s; h.pop(); p[i]++; cnt += x[i][m-p[i]] + x[i][k-p[i]]; if (p[i] < k) h.emplace(x[i][m-p[i]-1] + x[i][k-p[i]-1],i); } vi l(n),r(n,m-1); for (int i = 0; i < k; i++) { int up=0,un=0; vi b; for (int j = 0; j < n; j++) { if (p[j]==0) { un += 1; ans[j][l[j]++]=i; } else if (p[j] == k-i) { up += 1; p[j] -= 1; ans[j][r[j]--]=i; } else b.push_back(j); } while (un++<n/2) { int j = b[sz(b)-1]; b.pop_back(); ans[j][l[j]++]=i; } while (up++<n/2) { int j = b[sz(b)-1]; b.pop_back(); p[j] -= 1; ans[j][r[j]--]=i; } } allocate_tickets(ans); return cnt; }
#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...