-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1538A.cpp
More file actions
67 lines (57 loc) · 1.36 KB
/
1538A.cpp
File metadata and controls
67 lines (57 loc) · 1.36 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <set>
#include <queue>
#include <sstream>
using namespace std;
using p = pair<int, int>;
using ll = long long;
const int MAX = 10e+6;
const int INF = 0x66554433;
vector<string> split(string input, char delimiter) {
vector<string> answer;
stringstream ss(input);
string temp;
while (getline(ss, temp, delimiter)) {
answer.push_back(temp);
}
return answer;
}
inline void Quick_IO() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
int calc(int left, int right, int index){
return min(index - left, abs(right-index-1));
}
int main() {
Quick_IO();
int t;
cin >> t;
while (t--) {
int n;
int answer = 0;
cin >> n;
deque<int> arr;
int x1, x2;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
arr.push_back(a);
if (a == 1) x1 = i;
if (a == n) x2 = i;
}
vector<int> temp;
temp.push_back(max(x1, x2)+1);
temp.push_back(n-min(x1, x2));
temp.push_back(calc(0, n, x1)+calc(0, n, x2)+2);
// cout<<calc(0, n, x1)<<" "<<calc(0, n, x2)<<" "<<d<<endl;
cout<<*min_element(temp.begin(), temp.end())<<"\n";
}
return 0;
}