#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, ans, p, j, s;
void Dfs(ll a[], ll moves) {
if ( moves < ans) return;
if ( moves == 0) return ;
s = n;
for (ll i = 1; i <= n; i ++) {
if ( a[i] == (n - i + 1)) s --;
}
if ( s == 0) {
ans =max (ans, moves);
return;
}
for (ll i = 1; i <= n; i ++) {
reverse(a + i,a +n + 1);
Dfs(a, moves - 1);
reverse(a + i, a + n + 1);
}
return ;
}
int main() {
ll i, t, r;
cin >> t;
while ( t --) {
cin >> n;
ans = -1e9;
ll a[n + 2];
vector < pair < ll, ll > > v;
for (i = 1; i <= n; i ++) {
cin >> a[i];
v.push_back(make_pair(a[i], i));
}
sort (v.begin(), v.end());
for ( i = 0; i < n; i ++) {
a[v[i].second ] = i + 1;
}
Dfs(a, min(2*n, 10ll));
cout << 2 * n - ans << endl;
}
}
Compilation message
pancake.cpp: In function 'int main()':
pancake.cpp:26:11: warning: unused variable 'r' [-Wunused-variable]
26 | ll i, t, r;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
943 ms |
300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1068 ms |
340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |