# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
498203 |
2021-12-24T15:27:57 Z |
inksamurai |
Drvca (COCI19_drvca) |
C++17 |
|
1000 ms |
1476 KB |
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _32bB6rn ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
using pii=pair<int,int>;
using vi=vector<int>;
using dq=deque<int>;
int main(){
_32bB6rn;
int n;
cin>>n;
vi a(n);
rep(i,n) cin>>a[i];
sort(all(a));
auto g=[](dq up,dq dw){
if(!sz(up) or !sz(dw)) return;
int diff=0;
if(sz(up)>=2) diff=up[1]-up[0];
crep(i,2,sz(up)){
if(up[i]-up[i-1]!=diff){
return;
}
}
diff=0;
if(sz(dw)>=2) diff=dw[1]-dw[0];
crep(i,2,sz(dw)){
if(dw[i]-dw[i-1]!=diff){
return;
}
}
cout<<sz(up)<<"\n";
for(auto x : up){
cout<<x<<" ";
}
cout<<"\n";
cout<<sz(dw)<<"\n";
for(auto x : dw){
cout<<x<<" ";
}
cout<<"\n";
exit(0);
};
auto f=[&](int i,int diff){
dq up={a[i]},dw;
rep(type,2){
int j=i+(type==0?1:-1);
while((type==0?j<n:j>=0)){
while((type==0?j<n and a[j]-up.back()!=diff:j>=0 and up.front()-a[j]!=diff)){
if(type==0) dw.pb(a[j]);
else dw.push_front(a[j]);
j=j+(type==0?1:-1);
}
if((type==0?j<n:j>=0)){
if(type==0) up.pb(a[j]);
else up.push_front(a[j]);
int oj=(type==0?j+1:j-1);
int cnt=0;
while((type==0?oj<n:oj>=0)){
if(type==0) dw.pb(a[oj]);
else dw.push_front(a[oj]);
oj+=(type==0?1:-1);
cnt++;
}
if(type==1) g(up,dw);
rep(_,cnt){
if(type==0) dw.pop_back();
else dw.pop_front();
}
j=j+(type==0?1:-1);
}
}
}
g(up,dw);
};
rep(i,n-1){
if(i+2<n){
if(a[i+1]-a[i]!=a[i+2]-a[i+1]){
f(i,a[i+2]-a[i]);
f(i,a[i+1]-a[i]);
f(i+1,a[i+2]-a[i+1]);
break;
}
}
}
f(0,a[1]-a[0]);
dq up,dw;
rep(_,2){
for(int i=_;i<n;i+=2){
if(_==0) up.pb(a[i]);
else dw.pb(a[i]);
}
}
g(up,dw);
cout<<"-1\n";
//
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1078 ms |
1476 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |