#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define int long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define inf 1000000009
#define MOD 1000000007
#define lim 200005
using namespace std;
void solve(){
int n; cin >> n;
int arr[n+1];
for(int i=1; i<=n; i++) cin >> arr[i];
sort(arr+1, arr+n+1);
int took[n+1];
vi vec;
for(int sec=2; sec<=n; sec++){
vec.clear();
vec.pb(arr[1]); vec.pb(arr[sec]);
memset(took, 0, sizeof(took));
took[1] = took[sec] = 1;
int next = 2*arr[sec] - arr[1];
int ptr=sec;
while(ptr<n){
ptr++;
if(arr[ptr]<next) continue;
if(arr[ptr]==next){
vec.pb(arr[ptr]);
took[ptr]=1;
next = next + arr[sec] - arr[1];
}
else{
break;
}
}
int dif=-1, las=0, flag=0;
for(int i=1; i<=n; i++){
if(took[i]) continue;
if(las==0){
las = arr[i];
continue;
}
if(dif==-1){
dif = arr[i]-las;
las = arr[i];
continue;
}
if(arr[i] != las+dif){
flag = 1;
break;
}
las = arr[i];
}
if(flag) continue;
if(vec.size()==n){
cout << "1\n" << arr[1] << endl;
cout << n-1 << endl;
for(int i=2; i<=n; i++) cout << arr[i] << " ";
return;
}
cout << vec.size() << endl;
for(auto i:vec) cout << i << " ";
cout << endl << n-vec.size() << endl;
for(int i=1; i<=n; i++) if(!took[i]) cout << arr[i] << " ";
return;
}
cout << -1 << endl;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
int t=1;
//cin >> t;
while(t--) solve();
}
Compilation message
drvca.cpp: In function 'void solve()':
drvca.cpp:75:22: 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]
75 | if(vec.size()==n){
| ~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
3548 KB |
Output is correct |
2 |
Correct |
23 ms |
3544 KB |
Output is correct |
3 |
Correct |
20 ms |
3544 KB |
Output is correct |
4 |
Correct |
23 ms |
3396 KB |
Output is correct |
5 |
Correct |
20 ms |
3548 KB |
Output is correct |
6 |
Correct |
20 ms |
3536 KB |
Output is correct |
7 |
Correct |
21 ms |
3536 KB |
Output is correct |
8 |
Correct |
22 ms |
3548 KB |
Output is correct |
9 |
Execution timed out |
1065 ms |
2528 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |