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>
#define F first
#define S second
#define int long long
#define pb push_back
using namespace std;
const int N=1e6,M=2e3+1,mod=1e9+7;
int a[N],vis[N];map<int,int>mp;
main(){
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i],mp[a[i]]++;
sort(a,a+n);
int Final_ans=0;
vector<int>v,vv;
if(n==2){
cout<<1<<endl;
cout<<a[0]<<endl;
cout<<1<<endl;
cout<<a[1]<<endl;
return 0;
}
for(int num=2;num<n-1;num++){
if(Final_ans)
break;
for(int i=1;i<n;i++){
if(Final_ans)
break;
int x=a[i]-a[0];
if(x==0&&mp[a[0]]<num)
continue;
if(x%(num-1)==0){
int diff=x/(num-1);
v.clear(),vv.clear();
for(int j=0;j<n;j++)
vis[j]=0;
v.pb(a[0]);
vis[0]=1;
int lst=a[0];
for(int j=1;j<=i;j++){
if(a[j]==lst+diff){
v.pb(a[j]),lst=a[j],vis[j]=1;
}
}
for(int j=1;j<n;j++)
if(vis[j]==0)
vv.pb(a[j]);
if(v.size()!=num)
continue;
int ok=0,diff2;
if(vv.size()>1){
diff2=vv[1]-vv[0];
for(int j=1;j<vv.size();j++)
if(vv[j]!=vv[j-1]+diff2)
ok=1;
if(ok==1)
continue;
}
Final_ans=1;
}
}
}
if(Final_ans==1){
cout<<v.size()<<endl;
for(int i=0;i<v.size();i++)
cout<<v[i]<<" ";
cout<<endl;
cout<<vv.size()<<endl;
for(int i=0;i<vv.size();i++)
cout<<vv[i]<<" ";
cout<<endl;
}
else
cout<<"-1"<<endl;
return 0;
}
Compilation message (stderr)
drvca.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
9 | main(){
| ^~~~
drvca.cpp: In function 'int main()':
drvca.cpp:72:28: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
72 | if(v.size()!=num)
| ~~~~~~~~^~~~~
drvca.cpp:80:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(int j=1;j<vv.size();j++)
| ~^~~~~~~~~~
drvca.cpp:101:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
drvca.cpp:107:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
107 | for(int i=0;i<vv.size();i++)
| ~^~~~~~~~~~
# | 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... |