# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
601294 | definitelynotmee | Carnival Tickets (IOI20_tickets) | C++17 | 1169 ms | 187508 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "tickets.h"
#include <vector>
#include<bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
using namespace std;
template <typename T>
using matrix = vector<vector<T>>;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INFL = (1LL<<62)-1;
const int INF = (1<<30)-1;
const double EPS = 1e-7;
const int MOD = 1e9 + 7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
const int MAXN = 1e6+1;
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
matrix<int> group(n,vector<int>(m,-1));
ll resp = 0;
vector<int> minuscount(n,k);
priority_queue<pii> pq;
for(int i = 0; i < n; i++){
for(int j = 0; j < k; j++){
resp-=x[i][j];
pq.push({x[i][j]+x[i][m+j-k],i});
}
}
for(int i = 0; i < n*k/2; i++){
pii cur = pq.top();
pq.pop();
resp+=cur.ff;
minuscount[cur.ss]--;
}
vector<pii> minus, plus;
minus.reserve(n*k/2);
plus.reserve(n*k/2);
for(int i = 0; i < n; i++){
for(int j = 0; j < minuscount[i]; j++){
minus.push_back({i,j});
}
for(int j = m-1; j >= m-(k-minuscount[i]); j--){
plus.push_back({i,j});
}
}
vector<set<int>> occupy(k);
vector<int> curid(n);
int id = 0;
for(pii i : plus){
occupy[id].insert(i.ff);
group[i.ff][i.ss] = id;
id = (id+1)%k;
}
for(pii i : minus){
while(!(occupy[curid[i.ff]].size() < n && !occupy[curid[i.ff]].count(i.ff))){
curid[i.ff]++;
//assert(curid[i.ff] < k);
}
occupy[curid[i.ff]].insert(i.ff);
group[i.ff][i.ss] = curid[i.ff];
curid[i.ff]++;
}
allocate_tickets(group);
return resp;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |