Submission #442867

# Submission time Handle Problem Language Result Execution time Memory
442867 2021-07-09T10:05:27 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());

    vector<int>v0, v1;
    v0.push_back(a[0]);
    int p = 1;
    while(max(v0.size(), v1.size())<2) {
        int dif = a[p] - v0[0];
        int last = a[p];
        vector<int>v3 = v1;
        for(int i=p+1; i<N; ++i) {
            if(a[i]-last == dif) last = a[i];
            else v3.push_back(a[i]);
        }
        bool evenGap = true;
        for(int i=2; i<v3.size(); ++i) {
            evenGap &= v3[i]-v3[i-1]==v3[i-1]-v3[i-2];
        }
        if(evenGap) {
            v0.push_back(a[p++]);
            break;
        } else {
            v1.push_back(a[p++]);
        }
    }
    if(v0.size()==1) swap(v0, v1);
    int last = v0[1], dif = v0[1] - v0[0];
    for(int i=p; i<N; ++i) {
        if(dif + last == a[i]) v0.push_back(a[i]), last = a[i];
        else v1.push_back(a[i]);
    }
    bool evenGap = true;
    for(int i=2; i<v1.size(); ++i) {
        evenGap &= v1[i]-v1[i-1]==v1[i-1]-v1[i-2];
    }
    if(v1.empty()) v1.push_back(v0.back()), v0.pop_back();

    if(evenGap) {
        assert((int)v0.size()+v1.size()==N);
        cout << v0.size() << '\n';
        for(auto it : v0) cout << it << ' ';
        cout << '\n';
        cout << v1.size() << '\n';
        for(auto it : v1) cout << it << ' ';
        cout << '\n';
    } else 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);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    PlayGround();

    return 0;
}

Compilation message

drvca.cpp: In function 'void PlayGround()':
drvca.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for(int i=2; i<v3.size(); ++i) {
      |                      ~^~~~~~~~~~
drvca.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i=2; i<v1.size(); ++i) {
      |                  ~^~~~~~~~~~
In file included from /usr/include/c++/10/ext/pb_ds/detail/pat_trie_/pat_trie_.hpp:45,
                 from /usr/include/c++/10/ext/pb_ds/detail/container_base_dispatch.hpp:90,
                 from /usr/include/c++/10/ext/pb_ds/assoc_container.hpp:48,
                 from drvca.cpp:2:
drvca.cpp:54:40: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |         assert((int)v0.size()+v1.size()==N);
      |                ~~~~~~~~~~~~~~~~~~~~~~~~^~~
drvca.cpp: In function 'int main()':
drvca.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         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 -