답안 #202490

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
202490 2020-02-16T11:35:04 Z rdd6584 Drvca (COCI19_drvca) C++14
110 / 110
184 ms 37472 KB
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int>> pq;

vector<int> v;
multiset<int> se, tmp;

int vec[100000];
int n;

void print() {
    printf("%d\n", sz(v));
    for (int i = 0; i < sz(v); i++)
        printf("%d ", v[i]);
    printf("\n%d\n", sz(tmp));
    for (int i : tmp)
        printf("%d ", i);
    exit(0);
}
void check() {
    if (sz(v) == n) {
        se.insert(v.back());
        v.pop_back();
    }

    vector<int> vtmp = v;
    multiset<int> stmp = se;
    tmp = se;
    if (sz(se) == 1) print();
    int kk = *(++se.begin());
    int d = kk - *se.begin();

    kk = *(--(--se.end()));
    d = min(d, *(--se.end()) - kk);
    int next = *(--se.end());

    while (!se.empty()) {
        auto t = se.find(next);
        if (t == se.end()) {
            if (sz(v) >= 2 && next == v.back()) {
                v.pop_back();
                se.insert(next);
                tmp.insert(next);
                continue;
            }
            else break;
        }
        se.erase(t);
        next -= d;
    }
    if (se.empty()) print();

    v = vtmp;
    se = stmp;
    tmp = se;

    kk = *(++se.begin());
    d = kk - *se.begin();
    kk = *(--(--se.end()));
    d = min(d, *(--se.end()) - kk);
    next = v.back();
    while (!se.empty()) {
        auto t = se.find(next);
        if (t == se.end()) {
            if (sz(v) >= 2 && next == v.back()) {
                v.pop_back();
                se.insert(next);
                tmp.insert(next);
                continue;
            }
            else break;
        }
        se.erase(t);
        next -= d;
    }
    if (se.empty()) print();
}

int main() {
    scanf("%d", &n);

    for (int i = 0; i < n; i++)
        scanf("%d", &vec[i]);
    sort(vec, vec + n);

    if (n == 2) { return !printf("1\n%d\n1\n%d", vec[0], vec[1]); }

    // 1~2 등차 해보고 안되면..
    int d = 0;
    v.push_back(vec[0]);
    v.push_back(vec[1]);
    d = vec[1] - vec[0];

    for (int i = 2; i < n; i++) se.insert(vec[i]);
    int next = vec[1] + d;

    while (!se.empty()) {
        auto t = se.find(next);
        if (t == se.end()) break;
        v.push_back(*t);
        se.erase(t);
        next += d;
    }
    check();


    v.push_back(vec[0]);
    v.push_back(vec[2]);
    d = vec[2] - vec[0];

    se.insert(vec[1]);
    for (int i = 3; i < n; i++) se.insert(vec[i]);
    next = vec[2] + d;

    while (!se.empty()) {
        auto t = se.find(next);
        if (t == se.end()) break;
        v.push_back(*t);
        se.erase(t);
        next += d;
    }
    check();


    v.push_back(vec[1]);
    v.push_back(vec[2]);
    d = vec[2] - vec[1];

    se.insert(vec[0]);
    for (int i = 3; i < n; i++) se.insert(vec[i]);
    next = vec[2] + d;

    while (!se.empty()) {
        auto t = se.find(next);
        if (t == se.end()) break;
        v.push_back(*t);
        se.erase(t);
        next += d;
    }
    check();

    printf("-1");
}

Compilation message

drvca.cpp: In function 'int main()':
drvca.cpp:96:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
drvca.cpp:99:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &vec[i]);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 6 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 6 ms 504 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 380 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 4 ms 280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 9212 KB Output is correct
2 Correct 88 ms 9208 KB Output is correct
3 Correct 79 ms 9180 KB Output is correct
4 Correct 77 ms 9208 KB Output is correct
5 Correct 84 ms 9212 KB Output is correct
6 Correct 78 ms 9208 KB Output is correct
7 Correct 78 ms 9212 KB Output is correct
8 Correct 80 ms 9208 KB Output is correct
9 Correct 79 ms 8568 KB Output is correct
10 Correct 77 ms 9208 KB Output is correct
11 Correct 59 ms 6392 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 6 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 6 ms 504 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 380 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 4 ms 280 KB Output is correct
31 Correct 79 ms 9212 KB Output is correct
32 Correct 88 ms 9208 KB Output is correct
33 Correct 79 ms 9180 KB Output is correct
34 Correct 77 ms 9208 KB Output is correct
35 Correct 84 ms 9212 KB Output is correct
36 Correct 78 ms 9208 KB Output is correct
37 Correct 78 ms 9212 KB Output is correct
38 Correct 80 ms 9208 KB Output is correct
39 Correct 79 ms 8568 KB Output is correct
40 Correct 77 ms 9208 KB Output is correct
41 Correct 59 ms 6392 KB Output is correct
42 Correct 5 ms 256 KB Output is correct
43 Correct 82 ms 7928 KB Output is correct
44 Correct 164 ms 21312 KB Output is correct
45 Correct 83 ms 10872 KB Output is correct
46 Correct 80 ms 8184 KB Output is correct
47 Correct 160 ms 25984 KB Output is correct
48 Correct 83 ms 11512 KB Output is correct
49 Correct 76 ms 7416 KB Output is correct
50 Correct 184 ms 37472 KB Output is correct
51 Correct 85 ms 10360 KB Output is correct
52 Correct 70 ms 6392 KB Output is correct
53 Correct 150 ms 25276 KB Output is correct
54 Correct 87 ms 11128 KB Output is correct
55 Correct 72 ms 6392 KB Output is correct
56 Correct 63 ms 6396 KB Output is correct
57 Correct 60 ms 6416 KB Output is correct
58 Correct 5 ms 256 KB Output is correct