# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
430622 | TryMax | Carnival Tickets (IOI20_tickets) | C++17 | 1 ms | 232 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"
#ifdef LOCAL
#include "grader.cpp"
#endif // LOCAL
#include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define pb push_back
using namespace std;
const int N = 2e5 + 10;
int have[N];
ll cost(vector<int> a){
sort(a.begin(), a.end());
int n = a.size();
ll ans = 0;
for(int i = 0; i < n / 2; ++i)
ans += a[n / 2] - a[i];
for(int i = n / 2; i < n; ++i)
ans += a[i] - a[n / 2];
return ans;
}
ll find_maximum(int k, vector<vector<int>> x){
int n = x.size();
int m = x[0].size();
vector<pair<int, pair<int, int>>> a;
for(int i = 0; i < n; ++i)
for(int j = 0; j < m; ++j)
a.pb({x[i][j], {i, j}});
sort(a.begin(), a.end());
vector<vector<int>> ans;
ans.resize(n);
for(int i = 0; i < n; ++i){
ans[i].resize(m);
for(int j = 0; j < m; ++j)
ans[i][j] = -1;
}
int num = 0, ans1 = 0;
vector<int> now;
int l = 0, r = a.size() - 1;
while(num < k){
while(l < r && have[a[l].s.f])
++l;
ans[a[l].s.f][a[l].s.s] = num;
now.pb(a[l].f);
have[a[l].s.f] = 1;
while(l < r && have[a[r].s.f])
--r;
ans[a[r].s.f][a[r].s.s] = num;
have[a[r].s.f] = 1;
now.pb(a[r].f);
if(now.size() == n){
ans1 += cost(now);
now.clear();
for(int i = 0; i < n; ++i)
have[i] = 0;
++num;
}
++l, --r;
}
allocate_tickets(ans);
return ans1;
}
/*
2 3 2
0 2 5
1 1 3
7
0 -1 1
-1 1 0
4 2 1
5 9
1 4
3 6
2 7
12
-1 0
0 -1
0 -1
-1 0
*/
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... |