#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
map<pii,int> memo[305];
map<pii,int> dir[305];
int A[305];
int n;
bool correct(int last,int diff,int x)
{
if(diff==-1) return true;
if(x-A[last]!=diff) return false;
return true;
}
int possible(int i,int last,int diff,int last2,int diff2)
{
if(i==n && last2!=-1) return 1;
else if(i==n && last2==-1) return 0;
pii state=make_pair(last,diff);
if(memo[i].find(state)==memo[i].end()){
memo[i][state]=0;
if(correct(last,diff,A[i])){
int newDiff=0;
if(last==-1) newDiff=-1;
else if(diff==-1) newDiff=A[i]-A[last];
else newDiff=diff;
memo[i][state]=possible(i+1,i,newDiff,last2,diff2);
dir[i][state]=0;
}
if(memo[i][state]==0){
if(correct(last2,diff2,A[i])){
int newDiff=0;
if(last2==-1) newDiff=-1;
else if(diff2==-1) newDiff=A[i]-A[last2];
else newDiff=diff2;
memo[i][state]=possible(i+1,last,diff,i,newDiff);
dir[i][state]=1;
}
}
}
return memo[i][state];
}
vector<int> A1;
vector<int> A2;
void getSolution(int i,int last,int diff,int last2,int diff2)
{
if(i==n) return;
pii state=make_pair(last,diff);
if(dir[i][state]==0){
A1.push_back(A[i]);
int newDiff=0;
if(last==-1) newDiff=-1;
else if(diff==-1) newDiff=A[i]-A[last];
else newDiff=diff;
getSolution(i+1,i,newDiff,last2,diff2);
}
else{
A2.push_back(A[i]);
int newDiff=0;
if(last2==-1) newDiff=-1;
else if(diff2==-1) newDiff=A[i]-A[last2];
else newDiff=diff2;
getSolution(i+1,last,diff,i,newDiff);
}
}
int main()
{
cin>>n;
for(int i=0;i<n;i++){
cin>>A[i];
}
sort(A,A+n);
if(possible(0,-1,-1,-1,-1)){
getSolution(0,-1,-1,-1,-1);
cout<<A1.size()<<'\n';
for(int x: A1){
cout<<x<<" ";
}
cout<<'\n';
cout<<A2.size()<<'\n';
for(int x: A2){
cout<<x<<" ";
}
cout<<'\n';
}
else
cout<<-1<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
8 ms |
1408 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
640 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
640 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
8 ms |
1408 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
640 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
640 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Runtime error |
10 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
32 |
Halted |
0 ms |
0 KB |
- |