Submission #443148

# Submission time Handle Problem Language Result Execution time Memory
443148 2021-07-09T19:47:49 Z Abrar_Al_Samit Drvca (COCI19_drvca) C++17
110 / 110
250 ms 7108 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
    
using namespace std;
using namespace __gnu_pbds;
    
    
#define debug(x) cerr << '[' << (#x) << "] = " << x << '\n';
    
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
    
void PlayGround() {
    int N; cin >> N;
    vector<int>a(N);
    for(int i=0; i<N; ++i) cin >> a[i];
    sort(a.begin(), a.end());
    
    if(N < 4) {
        cout << 1 << '\n' << a[0] << '\n' << N-1 << '\n';
        for(int i=1; i<N; ++i) cout << a[i] << ' ';
        cout << '\n';
        return;
    }
    auto print = [] (vector<int>&x, vector<int>&y) {
        if(y.empty()) y.push_back(x.back()), x.pop_back();
        cout << x.size() << '\n';
        for(auto it : x) cout << it << ' ';
        cout << '\n';
        cout << y.size() << '\n';
        for(auto it : y) cout << it << ' ';
        cout << "\n";
    };
    auto msTomp = [] (multiset<int>&ms, map<int,int>&mp) {
        auto it = ms.begin();
        auto it2 = it;
        ++it2;
        while(it2!=ms.end()) {
            mp[*it2-*it]++;
            ++it2, ++it;
        }
    };
    auto insertNew = [] (multiset<int>::iterator it, multiset<int>&ms, map<int,int>&mp) {
        if(it!=ms.begin() && next(it, 1)!=ms.end()) {
            int gap = *next(it, 1) - *prev(it, 1);
            mp[gap]--;
            if(mp[gap]==0) mp.erase(gap);
            mp[*it - *prev(it, 1)]++;
            mp[*next(it, 1) - *it]++;
        } else if(it!=ms.begin()) {
            mp[*it-*prev(it, 1)]++;
        } else if(next(it, 1)!=ms.end()) {
            mp[*next(it, 1)-*it]++;
        }
    };
    auto Process = [=] (vector<int>&x, int third=-1) {
        multiset<int>ms;
        map<int,int>mp;
        vector<int>y;
        int dif = x[1] - x[0];

        if(third!=-1) ms.insert(a[third]);
        for(int i=3; i<N; ++i) {
            if(a[i]-x.back()==dif) x.push_back(a[i]);
            else ms.insert(a[i]);
        }
        if(ms.empty()) {
            print(x, y);
            exit(0);
        }

        msTomp(ms, mp);
        for(int i=x.size(); i>0; --i) {
            if(i<x.size()) {
                ms.insert(x[i]);
                insertNew(ms.find(x[i]), ms, mp);
            }
            if(mp.size()<2) {
                for(auto it : ms) y.push_back(it);
                x.resize(i);
                print(x, y);
                exit(0);
            }
        }
    };
    
    vector<int>b = {0, 1, 2};
    do {
        vector<int>x = {a[b[0]], a[b[1]]};
        if(x[0]>x[1]) swap(x[0], x[1]);

        Process(x, b[2]);
    } while(next_permutation(b.begin(), b.end()));
    if(a[2]-a[1]!=a[1]-a[0]) {
        cout << -1 << '\n';
        return;
    }
    vector<int>x = {a[0], a[1], a[2]};
    Process(x);
    cout << -1 << '\n';
    
    
    #ifndef ONLINE_JUDGE
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}   
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    PlayGround();
    
    return 0;
}

Compilation message

drvca.cpp: In lambda function:
drvca.cpp:74:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             if(i<x.size()) {
      |                ~^~~~~~~~~
# 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 1 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 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
# 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 1 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 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 230 ms 7096 KB Output is correct
2 Correct 201 ms 6840 KB Output is correct
3 Correct 187 ms 6840 KB Output is correct
4 Correct 200 ms 6844 KB Output is correct
5 Correct 235 ms 7092 KB Output is correct
6 Correct 201 ms 6832 KB Output is correct
7 Correct 231 ms 7092 KB Output is correct
8 Correct 199 ms 6916 KB Output is correct
9 Correct 193 ms 6596 KB Output is correct
10 Correct 194 ms 6980 KB Output is correct
11 Correct 25 ms 2504 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
# 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 1 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 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 230 ms 7096 KB Output is correct
32 Correct 201 ms 6840 KB Output is correct
33 Correct 187 ms 6840 KB Output is correct
34 Correct 200 ms 6844 KB Output is correct
35 Correct 235 ms 7092 KB Output is correct
36 Correct 201 ms 6832 KB Output is correct
37 Correct 231 ms 7092 KB Output is correct
38 Correct 199 ms 6916 KB Output is correct
39 Correct 193 ms 6596 KB Output is correct
40 Correct 194 ms 6980 KB Output is correct
41 Correct 25 ms 2504 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 232 ms 6996 KB Output is correct
44 Correct 250 ms 6340 KB Output is correct
45 Correct 202 ms 6812 KB Output is correct
46 Correct 208 ms 6836 KB Output is correct
47 Correct 207 ms 6064 KB Output is correct
48 Correct 192 ms 6808 KB Output is correct
49 Correct 248 ms 7108 KB Output is correct
50 Correct 192 ms 5828 KB Output is correct
51 Correct 193 ms 6936 KB Output is correct
52 Correct 213 ms 6852 KB Output is correct
53 Correct 209 ms 6068 KB Output is correct
54 Correct 195 ms 6840 KB Output is correct
55 Correct 206 ms 6820 KB Output is correct
56 Correct 199 ms 6248 KB Output is correct
57 Correct 25 ms 2528 KB Output is correct
58 Correct 1 ms 204 KB Output is correct