# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
306902 |
2020-09-26T14:06:47 Z |
dolijan |
Drvca (COCI19_drvca) |
C++14 |
|
294 ms |
11512 KB |
#include<bits/stdc++.h>
using namespace std;
const int mn=1e5+100;
int a[mn];
bool check(int prvi,int drugi,int n)
{
vector<int> aa;
vector<int> bb;
multiset<int> preostali;
multiset<int> razlike;
multiset<int>::iterator it,ptr;
aa.push_back(a[prvi]);
aa.push_back(a[drugi]);
for(int i=0;i<drugi;i++)
{
if(i!=prvi) preostali.insert(a[i]);
}
for(int i=drugi+1;i<n;i++)
{
preostali.insert(a[i]);
}
it=preostali.begin();
ptr=it;
it++;
while(it!=preostali.end())
{
razlike.insert(*it-*ptr);
it++; ptr++;
}
int raz=a[drugi]-a[prvi];
for(int i=drugi+1;i<n;i++)
{
int zad=aa[aa.size()-1];
if(a[i]-zad==raz)
{
aa.push_back(a[i]);
it=preostali.find(a[i]);
multiset<int>::iterator kraj=preostali.end();
kraj--;
if(it==preostali.begin())
{
ptr=it;
ptr++;
preostali.erase(preostali.find(*it));
razlike.erase(razlike.find(*ptr-*it));
}
else if(it==kraj)
{
ptr=it;
ptr--;
preostali.erase(preostali.find(*it));
razlike.erase(razlike.erase(*it-*ptr));
}
else
{
ptr=it;
multiset<int>::iterator veci=it;
veci++;
ptr--;
preostali.erase(preostali.find(*it));
razlike.erase(razlike.find(*it-*ptr));
razlike.erase(razlike.find(*veci-*it));
razlike.insert(*veci-*ptr);
}
}
if(!razlike.empty())
{
it=razlike.begin();
ptr=razlike.end();
ptr--;
if(*it==*ptr) break;
}
}
if(!razlike.empty())
{
it=razlike.begin();
ptr=razlike.end();
ptr--;
if(*it!=*ptr) return false;
}
if((int)preostali.size()==0)
{
preostali.insert(aa[aa.size()-1]);
aa.pop_back();
}
cout<<aa.size()<<endl;
for(int i=0;i<aa.size();i++) cout<<aa[i]<<" ";
cout<<endl;
cout<<preostali.size()<<endl;
it=preostali.begin();
while(it!=preostali.end())
{
cout<<*it<<" ";
it++;
}
cout<<endl;
return true;
}
int 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;
}
else
{
if(!check(0,1,n))
{
if(!check(0,2,n))
{
if(!check(1,2,n))
{
cout<<-1<<endl;
}
}
}
}
}
Compilation message
drvca.cpp: In function 'bool check(int, int, int)':
drvca.cpp:87:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for(int i=0;i<aa.size();i++) cout<<aa[i]<<" ";
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
180 ms |
11508 KB |
Output is correct |
2 |
Correct |
161 ms |
11128 KB |
Output is correct |
3 |
Correct |
190 ms |
11508 KB |
Output is correct |
4 |
Correct |
163 ms |
11128 KB |
Output is correct |
5 |
Correct |
177 ms |
11376 KB |
Output is correct |
6 |
Correct |
161 ms |
11128 KB |
Output is correct |
7 |
Correct |
179 ms |
11512 KB |
Output is correct |
8 |
Correct |
163 ms |
11128 KB |
Output is correct |
9 |
Correct |
144 ms |
10744 KB |
Output is correct |
10 |
Correct |
173 ms |
11128 KB |
Output is correct |
11 |
Correct |
147 ms |
11256 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
31 |
Correct |
180 ms |
11508 KB |
Output is correct |
32 |
Correct |
161 ms |
11128 KB |
Output is correct |
33 |
Correct |
190 ms |
11508 KB |
Output is correct |
34 |
Correct |
163 ms |
11128 KB |
Output is correct |
35 |
Correct |
177 ms |
11376 KB |
Output is correct |
36 |
Correct |
161 ms |
11128 KB |
Output is correct |
37 |
Correct |
179 ms |
11512 KB |
Output is correct |
38 |
Correct |
163 ms |
11128 KB |
Output is correct |
39 |
Correct |
144 ms |
10744 KB |
Output is correct |
40 |
Correct |
173 ms |
11128 KB |
Output is correct |
41 |
Correct |
147 ms |
11256 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
174 ms |
11428 KB |
Output is correct |
44 |
Correct |
294 ms |
10308 KB |
Output is correct |
45 |
Correct |
137 ms |
10744 KB |
Output is correct |
46 |
Correct |
165 ms |
11256 KB |
Output is correct |
47 |
Correct |
283 ms |
10308 KB |
Output is correct |
48 |
Correct |
145 ms |
10744 KB |
Output is correct |
49 |
Correct |
173 ms |
11384 KB |
Output is correct |
50 |
Correct |
250 ms |
10184 KB |
Output is correct |
51 |
Correct |
141 ms |
10876 KB |
Output is correct |
52 |
Correct |
163 ms |
11228 KB |
Output is correct |
53 |
Correct |
279 ms |
10308 KB |
Output is correct |
54 |
Correct |
142 ms |
10872 KB |
Output is correct |
55 |
Correct |
170 ms |
11128 KB |
Output is correct |
56 |
Correct |
160 ms |
11256 KB |
Output is correct |
57 |
Correct |
144 ms |
11052 KB |
Output is correct |
58 |
Correct |
1 ms |
256 KB |
Output is correct |