General

# Author Problem Lang Verdict Time Memory Sent Judged
75501441 Practice:
Nikhil-2500
1330B - 40 GNU C++17 Wrong answer on test 2 77 ms 576 KB 2020-04-04 18:53:03 2020-04-04 18:53:03

→ Source
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
void test(int,vector<int> &ar);
int main()
{
int t;
cin>>t;
vector<int> arr[t];
int i,j;
int a;
for(i=0;i<t;i++)
{
cin>>a;
arr[i].resize(a);
for(j=0;j<a;j++)
cin>>arr[i][j];
}

for(i=0;i<t;i++)
{
test(arr[i].size(),arr[i]);
}
return 0;
}
void test(int a,vector<int> &ar)
{
int tno=0;
vector<int> nol,nor;
int        sum1=0,sum2=0;
vector<int> out1,out2;
int i,j,k;

//First Left priority ie reading array from left to right
//For dividing the array into two subarray left and right
for(i=0;i<a-1;i++)
{
if(i==0)
{
out1.push_back(ar[0]);
continue;
}
vector<int>::iterator it = find(out1.begin(), out1.end(), ar[i]);
if (it != out1.end())
{
//std::cout << "Element Found" << std::endl;   //to break when duplicate element found
break;
}
else
{
out1.push_back(ar[i]);
}
}
for(;i<a;i++)
{
out2.push_back(ar[i]);
}       //after this the array is divided into left(out1) and right(out2)
/*cout<<"\nFirst array=";
for(j=0;j<out1.size();j++)
cout<<out1[j]<<" ";
cout<<"\nSecond array=";
for(j=0;j<out2.size();j++)
cout<<out2[j]<<" ";
*/
sum1=0;                 //temp variable to store the sum of the subarray to see
sum2=0;                 //if it is forming permutation since sum should be n*(n+1)/2
for(j=0;j<out1.size();j++)
sum1+=out1[j];
for(j=0;j<out2.size();j++)
sum2+=out2[j];
int summ_n;
summ_n=out1.size()*(out1.size()+1)/2;
if(sum1!=summ_n) sum1=0;        //ie when not forming permutation
summ_n=out2.size()*(out2.size()+1)/2;
if(sum2!=summ_n) sum2=0;
if(sum1&&sum2)              // when a permutation is identified
{
tno++;                  // total number of ways
nol.push_back(out1.size());     //for no of elements in left subarray
nor.push_back(out2.size());     ////for no of elements in right subarray
}

//cout<<"\nRIGHT PRIORITY NOW"<<endl;
//Next Right Priority
out1.clear();
out2.clear();
for(i=a-1;i>0;i--)
{
if(i==a-1)
{
out2.push_back(ar[a-1]);
continue;
}
vector<int>::iterator it = find(out2.begin(), out2.end(), ar[i]);
if (it != out2.end())
{
//std::cout << "Element Found" << std::endl;
break;
}
else
{
out2.push_back(ar[i]);
}
}
for(;i>=0;i--)
{
out1.push_back(ar[i]);
}

sum1=0;
sum2=0;
for(j=0;j<out1.size();j++)
sum1+=out1[j];
for(j=0;j<out2.size();j++)
sum2+=out2[j];
summ_n=out1.size()*(out1.size()+1)/2;
if(sum1!=summ_n) sum1=0;
summ_n=out2.size()*(out2.size()+1)/2;
if(sum2!=summ_n) sum2=0;
if(sum1&&sum2)
{
tno++;
nol.push_back(out1.size());
nor.push_back(out2.size());
}
cout<<tno<<endl;
for(i=0;i<nol.size();i++)
{
cout<<nol[i]<<" "<<nor[i]<<endl;
}

}

?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
?
?
?