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 "gondola.h"
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define itr ::iterator
const int MAX=1e5;
int arr[MAX],fre[MAX];
int valid(int n,int inputSeq[])
{
int N=n,ok=1;
for(int A=0;A<N;A++)
{
fre[inputSeq[A]]++;
if(fre[inputSeq[A]]>1)
return 0;
}
for(int A=0;A<N;A++)
{
if(inputSeq[A]<=N)
{
ok=0;
inputSeq[A]--;
for(int B=A;B>=0;B--)
{
arr[B]=inputSeq[A];
inputSeq[A]--;
if(inputSeq[A]<0)
inputSeq[A]+=N;
}
inputSeq[A]=arr[A];
for(int B=A+1;B<N;B++)
{
inputSeq[A]++;
if(inputSeq[A]>=N)
inputSeq[A]=0;
arr[B]=inputSeq[A];
}
inputSeq[A]=arr[A]+1;
break;
}
}
if(ok)
return 1;
for(int A=0;A<N;A++)
arr[A]++;
// for(int A=0;A<N;A++)
/// cout<<arr[A]<<" ";
for(int A=0;A<N;A++)
{
// cout<<arr[A]<<" "<<inputSeq[A]<<"\n";
if(inputSeq[A]<=N and arr[A]!=inputSeq[A])
return 0;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
return -2;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
if(!valid(n,inputSeq))
return 0;
int cnt=0;
vector<int> vec;
for(int A=0;A<n;A++)
vec.pb(inputSeq[A]);
sort(vec.begin(),vec.end());
for(int A=0;A<vec.size();A++)
if(vec[A]==vec[A-1])
return 0;
for(int A=0;A<vec.size();A++)
if(vec[A]>n)
cnt++;
if(cnt==1 or cnt==3)
return 1;
for(int A=0;A<n;A++)
{
if(inputSeq[A]<=n)
continue;
for(int B=A+1;B<n;B++)
{
if(inputSeq[B]<=n)
continue;
else if(inputSeq[A]<inputSeq[B] or vec.back()-n<3)
return 1;
else
return 2;
}
}
return 2;
}
/*int main()
{
int n,inputSeq[]={1,2,6,7};
cout<<countReplacement(4,inputSeq);
return 0;
}*/
Compilation message (stderr)
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:81:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int A=0;A<vec.size();A++)
~^~~~~~~~~~~
gondola.cpp:84:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int A=0;A<vec.size();A++)
~^~~~~~~~~~~
# | 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... |
# | 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... |