This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#define oo 987654321
using namespace std;
int T, n, a[10100], b[10001];
bool cmp(int x, int y){ return x > y; }
void flip(int x)
{
for(int i = x ; i < n+x-i-1 ; i++ )
swap(a[i], a[n+x-i-1]);
}
int main()
{
ios::sync_with_stdio(false);
cin>>T;
while( T-- )
{
int cnt = 0;
cin>>n;
for(int i = 0 ; i < n ; i++ ) cin>>a[i], b[i] = a[i];
sort(b, b+n, cmp);
for(int i = 0 ; i < n ; i++ )
{
if( b[i] == a[i] ) continue;
if( b[i] == a[n-1] ) flip(i), cnt++;
else
{
int v;
for(int j = i ; j < n ; j++ ) if( a[j] == b[i] ){ v = j; break; }
flip(v), flip(i), cnt+=2;
}
}
cout<<cnt<<" ";
}
return 0;
}
Compilation message (stderr)
pancake.cpp: In function 'int main()':
pancake.cpp:33:21: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
int v;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |