이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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, woo=sec;
while(ptr<n){
ptr++;
if(arr[ptr]<next) continue;
else if(arr[ptr]==next){
vec.pb(arr[ptr]);
took[ptr]=1;
woo = ptr;
next = next + arr[sec] - arr[1];
}
else{
break;
}
}
int flag=0;
jump:
int dif=-1, las=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++;
break;
}
las = arr[i];
}
if(flag==1){
took[woo] = 0;
goto jump;
}
else if(flag==2) 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();
}
컴파일 시 표준 에러 (stderr) 메시지
drvca.cpp: In function 'void solve()':
drvca.cpp:83: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]
83 | if(vec.size()==n){
| ~~~~~~~~~~^~~
# | 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... |