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<bits/stdc++.h>
using namespace std;
bool czy(vector<int> V){
//for(int i=0; i<V.size(); i++)cout<<V[i]<<" ";
// cout<<"\n";
if(V.size()==0)return 0;
if(V.size()==1)return 1;
int d=V[1]-V[0];
for(int i=1; i<V.size(); i++)if(V[i]-V[i-1]!=d)return 0;
return 1;
}
void out(vector<int> V){
cout<<V.size()<<"\n";
for(int i:V)cout<<i<<" ";
cout<<"\n";
}
vector<int> V;
bool roz(int a, int d){
vector<int> A, B;
for(int i:V){
if(i==a)A.push_back(i), a+=d;
else B.push_back(i);
}
if(B.size()==0){
B.push_back(A.back());
A.pop_back();
}
if(czy(B)){
out(A);
out(B);
return 1;
}
B.push_back(A.back());
A.pop_back();
sort(B.begin(), B.end());
a=B.back();
d=-B[B.size()-2]+B.back();
int wsk=B.size()-1;
while(wsk>=0){
if(B[wsk]==a){
wsk--;
a-=d;
}
else if(A.size() && A.back()==a){
B.push_back(A.back());
A.pop_back();
a-=d;
}
else{
return 0;
}
}
if(wsk==-1){
sort(B.begin(), B.end());
out(A);
out(B);
return 1;
}
return 0;
}
int main(){
int n;
cin>>n;
V.resize(n);
for(int &i:V)cin>>i;
sort(V.begin(), V.end());
if(roz(V[0], V[1]-V[0]))return 0;
if(n==2){
//cout<<1<<"\n"<<V[0]<<"\n"<<1<<"\n"<<V[1]<<"\n";
return 0;
}
if(roz(V[0], V[2]-V[0]))return 0;
if(roz(V[1], V[2]-V[1]))return 0;
cout<<-1;
return 0;
}
Compilation message (stderr)
drvca.cpp: In function 'bool czy(std::vector<int>)':
drvca.cpp:9:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | for(int i=1; i<V.size(); i++)if(V[i]-V[i-1]!=d)return 0;
| ~^~~~~~~~~
# | 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... |