# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
874233 | Matjaz | Jousting tournament (IOI12_tournament) | C++14 | 1050 ms | 2188 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 <vector>
#include <algorithm>
#include <iostream>
using namespace std;
// Insight: each S[i] E[i] corresponds to some interval in the original set of positions
// The interval only matters if your player is in it - and there is a unique answer as to whether it wins or loses
// You can find the best position with a sweep.
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) {
vector<int> s(N+1);
s[0] = 0;
for (int i=1;i<=N;i++) s[i] = s[i-1] + (K[i-1] > R);
vector<pair<int,int> > sweep_events;
vector<pair<int,int> > positions(N);
vector<pair<int,int> > intervals(C);
for (int i=0;i<N;i++) positions[i] = make_pair(i,i);
for (int i=0;i<C;i++){
intervals[i] = make_pair(positions[S[i]].first, positions[E[i]].second);
positions[S[i]] = intervals[i];
for (int j=E[i]+1;j<N;j++) positions[S[i] + j - E[i]] = positions[j];
if (s[intervals[i].second] - s[intervals[i].first] == 0){
sweep_events.push_back(make_pair(intervals[i].first, 1));
sweep_events.push_back(make_pair(intervals[i].second + 1, -1));
}
}
sort(sweep_events.begin(), sweep_events.end());
int best_position = 0;
int best_wins = 0;
int wins = 0;
for (int i=0;i<sweep_events.size();i++){
wins += sweep_events[i].second;
if (wins > best_wins){
best_wins = wins;
best_position = sweep_events[i].first;
}
}
return best_position;
}
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... |