이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
//#include"grader.cpp"
#ifdef EVAL
#else
#include"grader.cpp"
#endif
using namespace std;
int a[5005],N,tree[20005],flag[20005];
int gt(int v,int l,int r,int ql,int qr){
int val=0;
for(int i=ql;i<=qr;i++)val+=a[i];
return val;
}
void upd(int v,int l,int r,int ql,int qr,int val){
for(int i=ql;i<=qr;i++)a[i]=val;
}
int GetBestPosition(int n,int C,int R,int *K,int *s,int *e){
N=n;
vector<int>S,E,v;
for(int i=0;i<N-1;i++)K[i]=(K[i]>R);
for(int i=0;i<N;i++)v.push_back(i);
for(int i=0;i<C;i++){
S.push_back(v[s[i]]);
E.push_back(v[e[i]]);
vector<int>temp;
for(int j=0;j<v.size();j++)if(!(s[i]<j&&j<=e[i]))temp.push_back(v[j]);
v.clear();
v.insert(v.end(),temp.begin(),temp.end());
}
int mx=-1,cnt,id;
for(int pos=0;pos<N;pos++){
for(int i=0;i<pos;i++)a[i]=K[i];
a[pos]=0;
for(int i=pos+1;i<N;i++)a[i]=K[i-1];
cnt=0;
for(int i=0;i<C;i++){
int tmp=gt(1,0,N-1,S[i],E[i]);
if(tmp){
upd(1,0,N-1,S[i],S[i],1);
upd(1,0,N-1,E[i],E[i],1);
}else if(S[i]<=pos&&pos<=E[i])cnt++;
}
if(cnt>mx){
mx=cnt;
id=pos;
}
}
return id;
}
/*
5 3 3
1
0
2
4
1 3
0 1
0 1
*/
컴파일 시 표준 에러 (stderr) 메시지
tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int j=0;j<v.size();j++)if(!(s[i]<j&&j<=e[i]))temp.push_back(v[j]);
| ~^~~~~~~~~
tournament.cpp:48:12: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
48 | return id;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |