Submission #521484

#TimeUsernameProblemLanguageResultExecution timeMemory
521484LptN21Drvca (COCI19_drvca)C++14
0 / 110
41 ms10976 KiB
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL);
#define PI acos(-1.0)
#define eps 1e-9
#define FF first
#define SS second
// VECTOR (6)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define uniq(v) sort(all( (v) )), (v).resize( unique(all( (v) )) - (v).begin() );
// BIT (6)
#define CNTBIT(x) __builtin_popcountll(x)
#define ODDBIT(x) __builtin_parityll(x)
#define MASK(i) (1LL<<(i))
#define BIT(x, i) (((x)>>(i))&1)
#define SUBSET(big, small) (((big)&(small))==(small))
#define MINBIT(x) (x)&(-x)
#define FIRSTBIT(x) __builtin_ctzll(x)
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, int> ii;

/* */
template<class T>
bool minimize(T &a, const T &b) {
    if(a > b) {a = b; return 1;}
    return 0;
}
template<class T>
bool maximize(T &a, const T &b) {
    if(a < b) {a = b; return 1;}
    return 0;
}
/* */

/* CODE BELOW */
const int N = 1e5 + 7, M = 1e9 + 7;
const int oo = 1e16 + 7;
const int MOD = 1e9 + 7;

int n;

int a[N];

void print(const vector<int> &A, const set<int> &B) {
    printf("%d\n", sz(A));
    for(int v:A) printf("%d ", v);
    printf("\n%d\n", sz(B));
    for(int v:B) printf("%d ", v);
    exit(0);
}

void solve(int first, int second) {
    vector<int> A; set<int> B, diffB;
    for(int i=1;i<=n;i++) B.insert(a[i]);
    A.pb(first), A.pb(second);
    B.erase(B.find(first));
    B.erase(B.find(second));

    int prv = -1, diff = second - first;
    for(int v:B) {
        if(prv != -1) diffB.insert(v - prv);
        prv = v;
    }
    prv = second + diff;

    for(;sz(A) < n;prv+= diff) {
        if(*diffB.begin() == *diffB.rbegin()) {
            print(A, B);
        }

        auto it = B.find(prv);
        if(it == B.end()) break;
        auto L = it, R = it;

        if(it != B.begin()) {
            L--; diffB.erase(diffB.find(*it - *L));
        }
        if(it != B.end()) {
            R++; diffB.erase(diffB.find(*R - *it));
            if(it != B.begin()) {
                diffB.insert(*R - *L);
            }
        }
        A.pb(prv); B.erase(B.find(prv));
    }
}

signed main() {
    //freopen("test.inp", "r", stdin);
    //freopen("test.out", "w", stdout);
    //fastIO;
    scanf("%d", &n);
    for(int i=1;i<=n;i++) scanf("%d", &a[i]);
    sort(a+1, a+n+1);

    solve(a[1], a[2]);
    solve(a[1], a[3]);
    solve(a[2], a[3]);

    printf("-1");

    return 0;
}

Compilation message (stderr)

drvca.cpp:44:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0000000000000008e+16' to '2147483647' [-Woverflow]
   44 | const int oo = 1e16 + 7;
      |                ~~~~~^~~
drvca.cpp: In function 'int main()':
drvca.cpp:99:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
drvca.cpp:100:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |     for(int i=1;i<=n;i++) scanf("%d", &a[i]);
      |                           ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...