Submission #443040

# Submission time Handle Problem Language Result Execution time Memory
443040 2021-07-09T14:07:48 Z Abrar_Al_Samit Drvca (COCI19_drvca) C++17
0 / 110
3 ms 588 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) {
        for(int i=2; i<x.size(); ++i) assert(x[i]-x[i-1]==x[i-1]-x[i-2]);
        for(int i=2; i<y.size(); ++i) assert(y[i]-y[i-1]==y[i-1]-y[i-2]);
    
        cout << x.size() << '\n';
        for(auto it : x) cout << it << ' ';
        cout << '\n';
        cout << y.size() << '\n';
        for(auto it : y) cout << it << ' ';
        cout << "\n";
    };
    vector<int>b = {0, 1, 2};
    do {
        vector<int>x = {a[b[0]], a[b[1]]};
        vector<int>y = {a[b[2]]};
        if(x[0]>x[1]) swap(x[0], x[1]);
        int dif = x[1] - x[0];
    
        //debug(x[0]) debug(x[1]) debug(y[0]) debug(y[1])
    
        for(int i=3; i<N; ++i) {
            if(a[i]-x.back()==dif) x.push_back(a[i]);
            else if(y.size()<2 || a[i]-y.back()==y[1]-y[0]) y.push_back(a[i]);
            else {
                if(x.back()-y.back()==y[1]-y[0] && a[i]-x.back()==y[1]-y[0]) {
                    y.push_back(x.back()), x.pop_back();
                    y.push_back(a[i]);
                } else break;
            }
        }
        if(int(x.size()+y.size())==N) {
            print(x, y);
            return;
        }
    } while(next_permutation(b.begin(), b.end()));
    vector<int>x = {a[0], a[1], a[2]}, y;
    if(x[2]-x[1]!=x[1]-x[0]) {
        cout << -1 << '\n';
        return;
    }
    bool takeLast = false;
    for(int i=3; i<N; ++i) {
        if(x[1]-x[0]==a[i]-x.back()) x.push_back(a[i]);
        else y.push_back(a[i]);
    }
    
    for(int i=2; i<y.size(); ++i) if(y[i]-y[i-1]!=y[i-1]-y[i-2]) {
        cout << -1 << '\n';
        return;
    }
    if(y.empty()) y.push_back(x.back()), x.pop_back();
    print(x, y);
    
    
    #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);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    PlayGround();
    
    return 0;
}

Compilation message

drvca.cpp: In lambda function:
drvca.cpp:26:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for(int i=2; i<x.size(); ++i) assert(x[i]-x[i-1]==x[i-1]-x[i-2]);
      |                      ~^~~~~~~~~
drvca.cpp:27:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         for(int i=2; i<y.size(); ++i) assert(y[i]-y[i-1]==y[i-1]-y[i-2]);
      |                      ~^~~~~~~~~
drvca.cpp: In function 'void PlayGround()':
drvca.cpp:71:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for(int i=2; i<y.size(); ++i) if(y[i]-y[i-1]!=y[i-1]-y[i-2]) {
      |                  ~^~~~~~~~~
drvca.cpp:65:10: warning: unused variable 'takeLast' [-Wunused-variable]
   65 |     bool takeLast = false;
      |          ^~~~~~~~
drvca.cpp: In function 'int main()':
drvca.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -