-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1021.cpp
46 lines (43 loc) · 1005 Bytes
/
1021.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <deque>
using namespace std;
int main()
{
deque<int> d; int idx, cnt, loc, answer =0, temp;
cin>> idx >> cnt;
for(int i =0; i< idx; i++){
d.push_back(i+1);
}
while(cnt--){
cin>> temp;
for(int i =0; i<d.size(); i++){
if(temp == d[i]){
loc = i;
break;
}
}
if(loc < d.size() - loc){
while(1){
if(d.front() == temp){
d.pop_front();
break;
}
++answer;
d.push_back(d.front());
d.pop_front();
}
}else{
while(1){
if(d.front() == temp){
d.pop_front();
break;
}
++answer;
d.push_front(d.back());
d.pop_back();
}
}
}
cout <<answer;
return 0;
}