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 <bits/stdc++.h>
using namespace std;
int l[5005], r[5005], RR[5005];
int in[5005];
int id[5005];
int p[5005];
int sc[5005];
int leftpos[5005];
int T[5005];
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) {
for (int i = 0; i < N; i++) {
in[i] = 1;
}
for (int i = 0; i < N-1; i++) K[i] = K[i] > R ? 1:0;
fill(l,l+5000,-1);
fill(r,r+5000,-1);
fill(id,id+5000,-1);
fill(p,p+5000,-1);
fill(T,T+5000,-1);
iota(RR,RR+5000,0);
for (int i = 0; i < C; i++){
int cur = 0;
for (int j = 0; j < N; j++){
cur += in[j];
if (cur == S[i]+1 && l[i] == -1) l[i] = j;
if (cur == E[i]+1 && r[i] == -1) r[i] = RR[j];
}
//printf("tourney %d covers <%d,%d>\n",i,l[i],r[i]);
for (int j = l[i]; j <= r[i]; j++){
in[j] = 0;
if (id[j] != -1 && p[id[j]] == -1){
//printf("setting parent of %d to be %d\n",id[j],i);
p[id[j]] = i;
}
id[j] = i;
if (T[j] == -1) T[j] = i;
}
RR[l[i]] = r[i];
in[l[i]] = 1;
}
for (int i = 0; i < N; i++){
//printf("%d ",T[i]);
}
for (int i = C-1; i >= 0; i--){
//printf("%d %d\n",l[i],r[i]);
int mx = 0;
int LEFT = -1;
for (int j = l[i]; j < r[i]; j++){
if (K[j]) mx = 1;
if (T[j] == i && LEFT == -1) LEFT = j;
}
if (mx == 1){
sc[i] = 0;
}
else{
//printf("will win tourney %d <%d,%d>\n",i,l[i],r[i]);
for (int j = l[i]; j < r[i]; j++) assert(K[j] != 1);
if (p[i] == -1) sc[i] = 1;
else sc[i] = sc[p[i]] + 1;
}
leftpos[i] = LEFT;
}
for (int i = 0; i < C; i++){
//printf("parent of tourney %d is tourney %d, leftpos %d\n",i,p[i],leftpos[i]);
}
int bestsc = 0;
int ans = N-1;
for (int i = 0; i < C; i++){
//printf("tourney %d has score %d, pos %d\n",i,sc[i],leftpos[i]);
if (bestsc < sc[i]){
bestsc = sc[i];
ans = leftpos[i];
//printf("tourney %d has score %d, pos %d\n",i,sc[i],leftpos[i]);
}
else if (bestsc == sc[i]){
//printf("tourney %d has score %d, pos %d\n",i,sc[i],leftpos[i]);
ans = min(ans,leftpos[i]);
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |