이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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) {
int best_position = 0;
int best_wins = 0;
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];
}
vector<int> s(N+1);
s[0] = 0;
for (int i=1;i<=N;i++) s[i] = s[i-1] + (K[i-1] > R);
for (int p=0;p<N;p++){
int wins = 0;
for (int i=0;i<C;i++){
if (intervals[i].first <= p && p <= intervals[i].second){
if (s[intervals[i].second] - s[intervals[i].first] == 0) wins++;
}
}
if (wins > best_wins){
best_wins = wins;
best_position = p;
}
}
return best_position;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |