# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
580597 |
2022-06-21T13:32:29 Z |
AGE |
Drvca (COCI19_drvca) |
C++14 |
|
364 ms |
18652 KB |
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define pb push_back
using namespace std;
const int N=1e6,M=2e3,mod=1e9+7;
multiset<int>st,stt;
pair<int,int>ans;
vector<int>v,v2;
map<int,int>mp;
int a[N];
main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
if(n==2){
cout<<1<<endl;
cout<<a[0]<<endl;
cout<<1<<endl;
cout<<a[1]<<endl;
return 0;
}
if(n==3){
cout<<2<<endl;
cout<<a[0]<<" "<<a[1]<<endl;
cout<<1<<endl;
cout<<a[2]<<endl;
return 0;
}
if(n==4){
cout<<2<<endl;
cout<<a[0]<<" "<<a[1]<<endl;
cout<<2<<endl;
cout<<a[2]<<" "<<a[3]<<endl;
return 0;
}
int ok=0;
int Final_ans=0;
for(int ii=0;ii<=2;ii++){
if(Final_ans!=0)
break;
for(int jj=ii+1;jj<=2;jj++){
if(Final_ans!=0)
break;
st.clear(),stt.clear();
int x=a[ii];
int y=a[jj];
int diff=y-x;
int lst=y;
for(int i=n-1;i>=0;i--)
if(i!=ii&&i!=jj)
lst=i;
for(int i=0;i<n;i++){
if(i==ii||i==jj)
continue;
st.insert(a[i]);
if(i==lst)
continue;
stt.insert(a[i]-a[lst]);
lst=i;
}
/*for(auto x:st)
cout<<x<<" ";
cout<<endl;
for(auto x:stt)
cout<<x<<" ";
cout<<endl;
cout<<endl;*/
int lst2=y,num=2;
if(*stt.begin()==*st.rbegin())
Final_ans=num,ans.F=ii,ans.S=jj;
for(int i=lst2+diff;i>=0;i+=diff){
//cout<<i<<"!"<<endl;
if(Final_ans)
break;
if(st.size()==1)
break;
if(st.find(i)==st.end())
break;
int x=i;
auto itt=--st.end();
auto itt2=st.find(i);
if(itt2==itt){
//cout<<"@#"<<endl;
auto it=--st.find(i);
int diff2=(abs(*it-x));
st.erase(st.find(i));
stt.erase(stt.find(diff2));
}
else if(st.find(i)==st.begin()){
auto ittt=++st.find(i);
int diff2=abs((*ittt)-x);
st.erase(st.find(i));
stt.erase(stt.find(diff2));
// cout<<diff2<<endl;
//cout<<"!@!"<<endl;
}
else{
//cout<<"FI"<<endl;
auto it=++st.find(i);
auto it2=--st.find(i);
int diff1=abs(*it-x);
int diff2=abs(*it2-x);
st.erase(st.find(i));
if(stt.size())
stt.erase(stt.find(diff1));
if(stt.size())
stt.erase(stt.find(diff2));
stt.insert(abs(*it-*it2));
}
num++;
if(*stt.begin()==*stt.rbegin())
Final_ans=num,ans.F=ii,ans.S=jj;
}
}
}
//cout<<Final_ans<<" "<<ans.F<<" "<<ans.S<<endl;
if(Final_ans==0){
cout<<"-1"<<endl;
return 0;
}
v.pb(a[ans.F]);
v.pb(a[ans.S]);
for(int i=0;i<n;i++)
mp[a[i]]++;
int diff3=a[ans.S]-a[ans.F];
mp[a[ans.F]]--;
mp[a[ans.S]]--;
for(int i=0;i<Final_ans-2;i++)
v.pb(v[v.size()-1]+diff3),mp[v[v.size()-1]]--;
for(int i=0;i<n;i++){
if(i==ans.F||i==ans.S)
continue;
if(mp[a[i]]==0)
continue;
v2.pb(a[i]);
mp[a[i]]--;
}
cout<<v.size()<<endl;
for(int i=0;i<v.size();i++)
cout<<v[i]<<" ";
cout<<endl;
cout<<v2.size()<<endl;
for(int i=0;i<v2.size();i++)
cout<<v2[i]<<" ";
cout<<endl;
return 0;
}
Compilation message
drvca.cpp:16:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
16 | main()
| ^~~~
drvca.cpp: In function 'int main()':
drvca.cpp:221:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
221 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
drvca.cpp:226:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
226 | for(int i=0;i<v2.size();i++)
| ~^~~~~~~~~~
drvca.cpp:54:9: warning: unused variable 'ok' [-Wunused-variable]
54 | int ok=0;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
304 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
304 KB |
Output is correct |
30 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
189 ms |
18532 KB |
Output is correct |
2 |
Correct |
192 ms |
13840 KB |
Output is correct |
3 |
Correct |
202 ms |
18540 KB |
Output is correct |
4 |
Correct |
175 ms |
13860 KB |
Output is correct |
5 |
Correct |
185 ms |
18652 KB |
Output is correct |
6 |
Correct |
167 ms |
14072 KB |
Output is correct |
7 |
Correct |
186 ms |
18648 KB |
Output is correct |
8 |
Correct |
183 ms |
13896 KB |
Output is correct |
9 |
Correct |
156 ms |
13968 KB |
Output is correct |
10 |
Correct |
168 ms |
15116 KB |
Output is correct |
11 |
Correct |
99 ms |
12340 KB |
Output is correct |
12 |
Correct |
1 ms |
244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
304 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
304 KB |
Output is correct |
30 |
Correct |
1 ms |
312 KB |
Output is correct |
31 |
Correct |
189 ms |
18532 KB |
Output is correct |
32 |
Correct |
192 ms |
13840 KB |
Output is correct |
33 |
Correct |
202 ms |
18540 KB |
Output is correct |
34 |
Correct |
175 ms |
13860 KB |
Output is correct |
35 |
Correct |
185 ms |
18652 KB |
Output is correct |
36 |
Correct |
167 ms |
14072 KB |
Output is correct |
37 |
Correct |
186 ms |
18648 KB |
Output is correct |
38 |
Correct |
183 ms |
13896 KB |
Output is correct |
39 |
Correct |
156 ms |
13968 KB |
Output is correct |
40 |
Correct |
168 ms |
15116 KB |
Output is correct |
41 |
Correct |
99 ms |
12340 KB |
Output is correct |
42 |
Correct |
1 ms |
244 KB |
Output is correct |
43 |
Correct |
183 ms |
17632 KB |
Output is correct |
44 |
Correct |
364 ms |
11448 KB |
Output is correct |
45 |
Correct |
140 ms |
16832 KB |
Output is correct |
46 |
Correct |
181 ms |
14148 KB |
Output is correct |
47 |
Correct |
240 ms |
11452 KB |
Output is correct |
48 |
Correct |
157 ms |
16756 KB |
Output is correct |
49 |
Correct |
211 ms |
17064 KB |
Output is correct |
50 |
Correct |
209 ms |
11448 KB |
Output is correct |
51 |
Correct |
148 ms |
16880 KB |
Output is correct |
52 |
Correct |
161 ms |
14176 KB |
Output is correct |
53 |
Correct |
252 ms |
11400 KB |
Output is correct |
54 |
Correct |
149 ms |
16720 KB |
Output is correct |
55 |
Correct |
185 ms |
13488 KB |
Output is correct |
56 |
Correct |
117 ms |
12392 KB |
Output is correct |
57 |
Correct |
96 ms |
13368 KB |
Output is correct |
58 |
Correct |
1 ms |
312 KB |
Output is correct |