Submission #1114823

# Submission time Handle Problem Language Result Execution time Memory
1114823 2024-11-19T16:30:32 Z Nipphitch Pancake (NOI12_pancake) C++14
12 / 25
4 ms 336 KB
#include <bits/stdc++.h>
using namespace std;

void slove(){
    int n,tmp=0,ans=0;
    vector <int> a,b;
    cin >> n;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        a.push_back(x);
        b.push_back(x);
    }
    sort(b.begin(),b.end(),greater <int>());
    for(int i=0;i<n && tmp<n;i++){
        if(a[tmp]==b[tmp]) tmp++;
        else if(a[n-1]==b[tmp]){
            reverse(a.begin()+tmp,a.end());
            ans++;
            tmp++;
        }
        else{
            for(int j=tmp+1;j<n-1;j++){
                if(a[j]==b[tmp]){
                    reverse(a.begin()+j,a.end());
                    ans++;
                    reverse(a.begin()+tmp,a.end());
                    ans++;
                    tmp++;
                }
            }
        }
    }
    cout << ans << "\n";
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tc=1;
    cin >> tc;
    while(tc--) slove();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -