# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
306813 | dolijan | Drvca (COCI19_drvca) | C++14 | 108 ms | 3376 KiB |
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;
const int mn=1e5+100;
int a[mn];
bool check(int prvi,int drugi,int n)
{
vector<int> aa;
vector<int> bb;
aa.push_back(a[prvi]);
aa.push_back(a[drugi]);
for(int i=0;i<drugi;i++)
{
if(i!=prvi) bb.push_back(a[i]);
}
int raz=a[drugi]-a[prvi];
for(int i=drugi+1;i<n;i++)
{
int zad=aa[aa.size()-1];
if(a[i]-zad==raz)
{
aa.push_back(a[i]);
}
else
{
bb.push_back(a[i]);
}
}
bool li=true;
if((int)bb.size()==0)
{
bb.push_back(aa[aa.size()-1]);
aa.pop_back();
}
else if(bb.size()>=2)
{
int rzl=bb[1]-bb[0];
for(int i=1;i<bb.size();i++)
{
if(bb[i]-bb[i-1]!=rzl) li=false;
}
}
if(li)
{
cout<<aa.size()<<endl;
for(int i=0;i<aa.size();i++) cout<<aa[i]<<" ";
cout<<endl;
cout<<bb.size()<<endl;
for(int i=0;i<bb.size();i++) cout<<bb[i]<<" ";
cout<<endl;
return true;
}
return false;
}
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
if(n==2)
{
cout<<1<<endl;
cout<<a[0]<<endl;
cout<<1<<endl;
cout<<a[1]<<endl;
}
else
{
if(!check(0,1,n))
{
if(!check(0,2,n))
{
if(!check(1,2,n))
{
cout<<-1<<endl;
}
}
}
}
}
Compilation message (stderr)
# | 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... |