이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// "Say:He is the Most Merciful,We have believed in him and upon him we have relied" [67:29]
#include<bits/stdc++.h>
using namespace std;
bool is(vector<int>&v){
if((int)v.size() == 1)return 1;
int d = abs(v[0] - v[1]);
for(int i=0; i<(int)v.size()-1; i++){
if((v[i+1] - v[i]) != d)return 0;
}
return 1;
}
void print(vector<int>&a, vector<int>&b){
cout << (int)a.size() << "\n";
for(int e:a)cout << e << " ";
cout << '\n';
cout << (int)b.size() << '\n';
for(int e:b)cout << e << ' ';
cout << '\n';
}
int main(){
int n; cin >> n;
vector<int>v(n);
map<int, int>mp;
for(int i=0; i<n; i++){
cin >> v[i];
mp[v[i]]++;
}
sort(v.begin(), v.end());
if(n == 2){
vector<int>a = {v[0]}, b = {v[1]};
print(a, b);
return 0;
}
if(n == 3){
vector<int>a = {v[0], v[1]}, b = {v[2]};
print(a, b);
return 0;
}
if(is(v)){
cout << (n>>1) << '\n';
for(int i=0; i<(n>>1); i++)cout << v[i] << ' ';
cout << '\n' << (n>>1) << '\n';
for(int i=n>>1; i<n; i++)cout << v[i] << ' ';
cout << '\n';
return 0;
}
vector<int>a, b;
int d = v[1] - v[0];
a.push_back(v[0]);
a.push_back(v[1]);
int ind = 1;
for(int i=2; i<n; i++){
if(v[i] == v[ind]+d)a.push_back(v[i]), ind++;
else b.push_back(v[i]);
}
if(is(a) and is(b)){
print(a, b);
}else {
a.clear();
b.clear();
a.push_back(v[0]);
b.push_back(v[1]);
a.push_back(v[2]);
d = v[2] - v[0], ind = 2;
for(int i=3; i<n; i++){
if(v[i] == v[ind]+d)a.push_back(v[i]), ind++; else b.push_back(v[i]);
}
if(is(a) and is(b)){
print(a, b);
}else {
a.clear();
b.clear();
a.push_back(v[0]);
b.push_back(v[1]);
b.push_back(v[2]);
d = v[2] - v[1], ind = 2;
for(int i=3; i<n; i++){
if(v[i] == v[ind]+d)b.push_back(v[i]), ind++; else a.push_back(v[i]);
}
print(a, b);
}
}
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... |