이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int LIMIT=(200000*2)+5;
int level[LIMIT];
int Objetivos, Rounds;
vector<pair<int,int>> Campo;
int bucket[LIMIT];
int bucle(){
int c1 = 1; bool myArcher=0;
for(int i=0;i<2*Objetivos;i++){
if(i == 0){
if(Campo[i].first == 1) c1 ++;
if(Campo[i].second == 1) c1++;
if(Campo[i].first==level[1] || Campo[i].second==level[1]) myArcher=1;
}else{
if(Campo[i].first)c1++;
if(Campo[i].second)c1++;
if(Campo[i].first==level[1] || Campo[i].second==level[1]) myArcher=1;
}
if(c1 > 1){
Campo.push_back(make_pair(1,0));
c1--;
} else if(c1 == 1){
if(myArcher){
Campo.push_back(make_pair(level[1],0));
myArcher=0;
if(i+1 >= Objetivos) return (Objetivos - ((Rounds - i+1) % Objetivos));
}else{
Campo.push_back(make_pair(0, 0));
}
}else{
Campo.push_back(make_pair(0, 0));
}
}
}
int nobucle(){
for(int i=0;i<=Objetivos;i++){
bucket[i]=0;
}
int pos=0;
for(int i=0;i<Objetivos;i++){
if(Campo[i].first==0) bucket[i+1]++;
if(Campo[i].second==0) bucket[i+1]++;
if(Campo[i].first==level[1] || Campo[i].second==level[1])pos=i+1;
}
int c0=bucket[1];
bool myArcher=0;
bucket[1]=0;
if(pos==1) myArcher=1;
for(int i=Objetivos;i>=2;i--){
if(pos==i)myArcher=1;
if(bucket[i]==0 && c0==0 && myArcher){
pos=i;
myArcher=0;
}else if(bucket[i]==0 && c0!=0){
c0--;
bucket[i]++;
}else if(bucket[i]>0){
c0+=bucket[i]-1;
bucket[i]=1;
}
}
c0=bucket[1];
myArcher=0;
if(pos==1) myArcher=1;
bucket[1]=0;
for(int i=Objetivos;i>=2;i--){
if(pos==i)myArcher=1;
if(bucket[i]==0 && c0==0 && myArcher){
pos=i;
myArcher=0;
}else if(bucket[i]==0 && c0!=0){
c0--;
bucket[i]++;
}else if(bucket[i]>0){
c0+=bucket[i]-1;
bucket[i]=1;
}
}
return pos;
}
int solve(int ini){
Campo.clear();
bool x,y;
for(int i=2, j=1; i<=2*Objetivos;i+=2,j++){
x=(level[i]<level[1])?1:0;
y=(level[i+1]<level[1])?1:0;
if(j==ini){
Campo.push_back(make_pair(x,level[1]));
i--;
}else Campo.push_back(make_pair(x,y));
}
int z=0;
if(level[1]<=Objetivos+1){
z=bucle();
}else{
z=nobucle();
}
return z;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie();
cin>>Objetivos>>Rounds;
for(int i=1;i<=Objetivos*2;i++){
cin>>level[i];
}
if(level[1]==1){
cout<<1<<'\n';
return 0;
}
int res,mpos=INT_MAX,pos;
for(int i=1;i<=Objetivos;i++){
pos=solve(i);
if(mpos>=pos){
mpos=pos;
res=i;
}
}
cout<<res;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
archery.cpp: In function 'int bucle()':
archery.cpp:35:1: warning: control reaches end of non-void function [-Wreturn-type]
35 | }
| ^
archery.cpp: In function 'int main()':
archery.cpp:119:9: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
119 | cout<<res;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |