#include<bits/stdc++.h>
using namespace std;
int r,n,yo;
vector<int>habilidades;
vector<pair<int,int>>campo;
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});
campo[pos].first=habilidades[0];
for(int i=1;i<n*2;i++){
if(campo[it].first==0){
campo[it].first=habilidades[i];
}else if(campo[it].second==0){
campo[it].second=habilidades[i];
}else{
it++;
i--;
}
}
for(int i=1;i<=r;i++){
ronda();
}
//for(auto x:campo)cout<<x.first<<' '<<x.second<<'\n';
for(int i=0;i<n;i++){
if(campo[i].first==yo or campo[i].second==yo)return i;
}
return n;
}
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;
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 |
316 KB |
Output is correct |
2 |
Execution timed out |
2072 ms |
324 KB |
Time limit exceeded |
3 |
Correct |
1678 ms |
296 KB |
Output is correct |
4 |
Execution timed out |
2086 ms |
336 KB |
Time limit exceeded |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Execution timed out |
2093 ms |
312 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
208 KB |
Output is correct |
2 |
Execution timed out |
2089 ms |
312 KB |
Time limit exceeded |
3 |
Execution timed out |
2086 ms |
336 KB |
Time limit exceeded |
4 |
Execution timed out |
2062 ms |
592 KB |
Time limit exceeded |
5 |
Execution timed out |
2075 ms |
5140 KB |
Time limit exceeded |
6 |
Execution timed out |
2053 ms |
208 KB |
Time limit exceeded |
7 |
Execution timed out |
2035 ms |
312 KB |
Time limit exceeded |
8 |
Execution timed out |
2052 ms |
692 KB |
Time limit exceeded |
9 |
Execution timed out |
2066 ms |
840 KB |
Time limit exceeded |
10 |
Execution timed out |
2037 ms |
336 KB |
Time limit exceeded |
11 |
Execution timed out |
2072 ms |
848 KB |
Time limit exceeded |
12 |
Execution timed out |
2078 ms |
336 KB |
Time limit exceeded |
13 |
Execution timed out |
2040 ms |
3768 KB |
Time limit exceeded |
14 |
Execution timed out |
2070 ms |
336 KB |
Time limit exceeded |
15 |
Execution timed out |
2051 ms |
1068 KB |
Time limit exceeded |
16 |
Correct |
44 ms |
312 KB |
Output is correct |
17 |
Execution timed out |
2094 ms |
336 KB |
Time limit exceeded |
18 |
Execution timed out |
2028 ms |
336 KB |
Time limit exceeded |
19 |
Execution timed out |
2059 ms |
324 KB |
Time limit exceeded |
20 |
Execution timed out |
2068 ms |
336 KB |
Time limit exceeded |
21 |
Execution timed out |
2063 ms |
848 KB |
Time limit exceeded |
22 |
Execution timed out |
2011 ms |
1024 KB |
Time limit exceeded |
23 |
Execution timed out |
2067 ms |
5420 KB |
Time limit exceeded |
24 |
Correct |
27 ms |
316 KB |
Output is correct |
25 |
Execution timed out |
2074 ms |
336 KB |
Time limit exceeded |
26 |
Execution timed out |
2053 ms |
332 KB |
Time limit exceeded |
27 |
Execution timed out |
2013 ms |
848 KB |
Time limit exceeded |
28 |
Execution timed out |
2021 ms |
3904 KB |
Time limit exceeded |
29 |
Execution timed out |
2068 ms |
328 KB |
Time limit exceeded |
30 |
Execution timed out |
2067 ms |
336 KB |
Time limit exceeded |
31 |
Execution timed out |
2001 ms |
840 KB |
Time limit exceeded |
32 |
Execution timed out |
2015 ms |
5212 KB |
Time limit exceeded |
33 |
Correct |
36 ms |
208 KB |
Output is correct |
34 |
Execution timed out |
2077 ms |
208 KB |
Time limit exceeded |
35 |
Execution timed out |
2063 ms |
336 KB |
Time limit exceeded |
36 |
Execution timed out |
2084 ms |
336 KB |
Time limit exceeded |
37 |
Execution timed out |
2090 ms |
720 KB |
Time limit exceeded |
38 |
Execution timed out |
2082 ms |
976 KB |
Time limit exceeded |
39 |
Execution timed out |
2079 ms |
208 KB |
Time limit exceeded |
40 |
Execution timed out |
2071 ms |
336 KB |
Time limit exceeded |
41 |
Execution timed out |
2074 ms |
336 KB |
Time limit exceeded |
42 |
Execution timed out |
2060 ms |
336 KB |
Time limit exceeded |
43 |
Execution timed out |
2085 ms |
336 KB |
Time limit exceeded |
44 |
Execution timed out |
2081 ms |
464 KB |
Time limit exceeded |
45 |
Execution timed out |
2069 ms |
848 KB |
Time limit exceeded |
46 |
Execution timed out |
2066 ms |
836 KB |
Time limit exceeded |
47 |
Execution timed out |
2024 ms |
5984 KB |
Time limit exceeded |