PRMA - Editorial

Practice
Contest Page

Author: Rohit Pradhan
Tester: Abhinav Prakash
Editorialist: Editorialist’s name

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Math

PROBLEM:

Check if the given permutation can be obtained from the permutation 1 2 … n using exactly one segment reversal. If it is possible, find the segment itself.

QUICK EXPLANATION:

If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers l, r (1 ≤ l < r ≤ n) which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 … n the given one.

SOLUTIONS:

Solution
#include <iostream>
using namespace std;
int a[1001], n, i, j, L, R;
int main(){
   cin>>n;
   for (i=1; i<=n; i++) 
   {
	    cin>>a[i];
	    if (a[i]!=i) 
	    {
		    R=i;
		    if (L==0) L=i;
	    }
    }
    for (i=L,j=R; i<=R; i++,j--) if (a[i]!=j) 
    {
	    cout<<"0 0"<<endl; return 0;
    }
    cout<<L<<" "<<R<<endl;
}

Honestly speaking, this is not the way you write an editorial. Quick Explanation briefs the solution, not describing the problem itself. You may edit all the editorials you’ve written so far, following the guidelines on writing an Editorial. :grinning: