Submission #521492

# Submission time Handle Problem Language Result Execution time Memory
521492 2022-02-02T08:59:07 Z LptN21 Drvca (COCI19_drvca) C++14
110 / 110
206 ms 12060 KB
#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 multiset<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; multiset<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; R++;

        if(it != B.begin()) {
            L--; diffB.erase(diffB.find(*it - *L));
        }
        if(R != B.end()) {
            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);

    if(n<=3) {
        printf("%d\n", n/2);
        for(int i=1;i<=n/2;i++) {
            printf("%d ", a[i]);
        }
        printf("\n%d\n", n-n/2);
        for(int i=n/2+1;i<=n;i++) {
            printf("%d ", a[i]);
        }
        return 0;
    }

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

    printf("-1");

    return 0;
}

Compilation message

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 time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 216 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 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 1 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 216 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 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 1 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 296 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 10948 KB Output is correct
2 Correct 78 ms 10976 KB Output is correct
3 Correct 101 ms 11064 KB Output is correct
4 Correct 71 ms 10948 KB Output is correct
5 Correct 91 ms 10936 KB Output is correct
6 Correct 77 ms 11028 KB Output is correct
7 Correct 82 ms 10948 KB Output is correct
8 Correct 68 ms 10944 KB Output is correct
9 Correct 70 ms 10656 KB Output is correct
10 Correct 94 ms 10984 KB Output is correct
11 Correct 59 ms 11064 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 216 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 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 1 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 296 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 86 ms 10948 KB Output is correct
32 Correct 78 ms 10976 KB Output is correct
33 Correct 101 ms 11064 KB Output is correct
34 Correct 71 ms 10948 KB Output is correct
35 Correct 91 ms 10936 KB Output is correct
36 Correct 77 ms 11028 KB Output is correct
37 Correct 82 ms 10948 KB Output is correct
38 Correct 68 ms 10944 KB Output is correct
39 Correct 70 ms 10656 KB Output is correct
40 Correct 94 ms 10984 KB Output is correct
41 Correct 59 ms 11064 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 80 ms 11920 KB Output is correct
44 Correct 203 ms 11076 KB Output is correct
45 Correct 68 ms 11364 KB Output is correct
46 Correct 76 ms 12008 KB Output is correct
47 Correct 183 ms 11040 KB Output is correct
48 Correct 63 ms 11328 KB Output is correct
49 Correct 82 ms 11972 KB Output is correct
50 Correct 153 ms 11024 KB Output is correct
51 Correct 66 ms 11476 KB Output is correct
52 Correct 72 ms 11952 KB Output is correct
53 Correct 206 ms 11036 KB Output is correct
54 Correct 64 ms 11332 KB Output is correct
55 Correct 92 ms 11928 KB Output is correct
56 Correct 72 ms 12060 KB Output is correct
57 Correct 57 ms 12004 KB Output is correct
58 Correct 0 ms 204 KB Output is correct