#include<bits/stdc++.h>
using namespace std;
int r,n,yo;
vector<int>habilidades;
vector<pair<int,int>>campo;
vector<int>posciciones;
void ronda(){
for(int i=0;i<n;i++){
if(campo[i].first>campo[i].second){
swap(campo[i].first,campo[i].second);
}
}
int aux=campo[0].second;
campo[0].second=campo[1].first;
for(int i=2;i<n;i++){
campo[i-1].first=campo[i].first;
}
campo[n-1].first=aux;
}
int comprueba(int pos){
int it=0;
campo.clear();
campo.resize(n,{0,0});
posciciones.clear();
posciciones.resize(n*2+2,0);
campo[pos].first=habilidades[0];
for(int i=1;i<n*2;i++){
if(campo[it].first==0){
campo[it].first=habilidades[i];
posciciones[i]=it;
}else if(campo[it].second==0){
campo[it].second=habilidades[i];
posciciones[i]=it;
}else{
it++;
i--;
}
}
for(int i=1;i<=2*n;i++){
ronda();
}
int acomodo=0;
for(int i=0;i<n;i++){
if(campo[i].first==yo or campo[i].second==yo)acomodo=i;
}
int restantes=r-2*n;
restantes%=n;
acomodo-=restantes;
acomodo+=n;
acomodo%=n;
return acomodo;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>r;
habilidades.resize(n*2+2,0);
campo.resize(n+2,{0,0});
for(int i=0;i<n*2;i++)cin>>habilidades[i];
yo=habilidades[0];
int ans=-1;
int minima=INT_MAX;
//cout<<"xd\n";
for(int i=0;i<n;i++){
int res=comprueba(i);
//for(auto x:campo)cout<<x.first<<' '<<x.second<<'\n';
//cout<<res<<'\n';
if(res<=minima){ans=i; minima=res;}
}
cout<<ans+1<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Execution timed out |
2066 ms |
316 KB |
Time limit exceeded |
3 |
Correct |
4 ms |
312 KB |
Output is correct |
4 |
Execution timed out |
2086 ms |
332 KB |
Time limit exceeded |
5 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
6 |
Incorrect |
20 ms |
312 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
21 ms |
312 KB |
Output is correct |
3 |
Execution timed out |
2088 ms |
324 KB |
Time limit exceeded |
4 |
Execution timed out |
2087 ms |
716 KB |
Time limit exceeded |
5 |
Execution timed out |
2071 ms |
4964 KB |
Time limit exceeded |
6 |
Correct |
24 ms |
204 KB |
Output is correct |
7 |
Correct |
1687 ms |
332 KB |
Output is correct |
8 |
Execution timed out |
2040 ms |
784 KB |
Time limit exceeded |
9 |
Execution timed out |
2082 ms |
972 KB |
Time limit exceeded |
10 |
Execution timed out |
2074 ms |
320 KB |
Time limit exceeded |
11 |
Execution timed out |
2084 ms |
972 KB |
Time limit exceeded |
12 |
Execution timed out |
2091 ms |
332 KB |
Time limit exceeded |
13 |
Execution timed out |
2068 ms |
3908 KB |
Time limit exceeded |
14 |
Execution timed out |
2078 ms |
460 KB |
Time limit exceeded |
15 |
Execution timed out |
2089 ms |
1356 KB |
Time limit exceeded |
16 |
Correct |
22 ms |
312 KB |
Output is correct |
17 |
Execution timed out |
2080 ms |
332 KB |
Time limit exceeded |
18 |
Execution timed out |
2091 ms |
332 KB |
Time limit exceeded |
19 |
Execution timed out |
2092 ms |
332 KB |
Time limit exceeded |
20 |
Execution timed out |
2084 ms |
460 KB |
Time limit exceeded |
21 |
Execution timed out |
2085 ms |
964 KB |
Time limit exceeded |
22 |
Execution timed out |
2087 ms |
1356 KB |
Time limit exceeded |
23 |
Execution timed out |
2068 ms |
5192 KB |
Time limit exceeded |
24 |
Incorrect |
22 ms |
204 KB |
Output isn't correct |
25 |
Execution timed out |
2083 ms |
332 KB |
Time limit exceeded |
26 |
Execution timed out |
2078 ms |
460 KB |
Time limit exceeded |
27 |
Execution timed out |
2087 ms |
968 KB |
Time limit exceeded |
28 |
Execution timed out |
2024 ms |
3976 KB |
Time limit exceeded |
29 |
Execution timed out |
2082 ms |
332 KB |
Time limit exceeded |
30 |
Execution timed out |
2094 ms |
460 KB |
Time limit exceeded |
31 |
Execution timed out |
2070 ms |
992 KB |
Time limit exceeded |
32 |
Execution timed out |
2044 ms |
5172 KB |
Time limit exceeded |
33 |
Incorrect |
23 ms |
204 KB |
Output isn't correct |
34 |
Incorrect |
22 ms |
204 KB |
Output isn't correct |
35 |
Execution timed out |
2062 ms |
320 KB |
Time limit exceeded |
36 |
Execution timed out |
2068 ms |
332 KB |
Time limit exceeded |
37 |
Execution timed out |
2083 ms |
848 KB |
Time limit exceeded |
38 |
Execution timed out |
2066 ms |
1100 KB |
Time limit exceeded |
39 |
Correct |
19 ms |
204 KB |
Output is correct |
40 |
Execution timed out |
2094 ms |
332 KB |
Time limit exceeded |
41 |
Execution timed out |
2064 ms |
332 KB |
Time limit exceeded |
42 |
Execution timed out |
2064 ms |
320 KB |
Time limit exceeded |
43 |
Execution timed out |
2066 ms |
460 KB |
Time limit exceeded |
44 |
Execution timed out |
2064 ms |
576 KB |
Time limit exceeded |
45 |
Execution timed out |
2085 ms |
972 KB |
Time limit exceeded |
46 |
Execution timed out |
2021 ms |
1028 KB |
Time limit exceeded |
47 |
Execution timed out |
2060 ms |
5700 KB |
Time limit exceeded |