#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define tc ll test;cin >> test;while(test--)
#define vi vector<ll>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define INF 1e18
#define MOD 1000000007
#define ff first
#define ss second
#define in >>
#define out <<
#define space << " " <<
#define spacef << " "
#define fo(i,a,b) for(ll i = a; i <= b; i++)
#define nextline out "\n"
#define print(x) for(auto i : x ) cout out i spacef
#define mmax(x,i) x = max(x,i)
#define mmin(x,i) x = min(x,i)
#define N 105
ll n;
ll sum = 0;
void go(ll i , vi a){
if(i == n) return;
ll maxv = -INF , maxp;
fo(j,i,n){
if(a[j] > maxv){
maxv = a[j];
maxp = j;
}
}
if(maxp == i){
go(i+1,a);
}
else if(maxp == n){
sum++;
reverse(a.begin()+i,a.begin()+n+1);
go(i+1,a);
}
else{
sum += 2;
reverse(a.begin()+maxp,a.begin()+n+1);
reverse(a.begin()+i,a.begin()+n+1);
go(i+1,a);
}
}
int main() {
fast;
tc{
cin in n;
vi a(n+5);
fo(i,1,n) cin in a[i];
sum = 0;
go(1,a);
cout out sum nextline;
}
return 0;
}
Compilation message
pancake.cpp: In function 'void go(long long int, std::vector<long long int>)':
pancake.cpp:44:7: warning: 'maxp' may be used uninitialized in this function [-Wmaybe-uninitialized]
44 | else if(maxp == n){
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |