답안 #1085679

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1085679 2024-09-08T14:59:48 Z serifefedartar Drvca (COCI19_drvca) C++17
110 / 110
105 ms 7984 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
#define f first
#define s second
#define LOGN 21
const ll MOD = 1e9 + 7;
const ll MAXN = 2e5 + 100;

multiset<int> other_sequence;
map<int,int> diff;
vector<int> h, sequence;
int cnt = 0;

void omit(int k) {
    auto u = other_sequence.lower_bound(k);
    int C = 0;
    if (u != other_sequence.begin()) {
        C++;
        int dd = *u - *prev(u);
        diff[dd]--;
        if (diff[dd] == 0)
            cnt--;
    }
    if (prev(other_sequence.end()) != u) {
        C++;
        int x = *u;
        u++;
        int dd = *u - x;
        u--;
        diff[dd]--;
        if (diff[dd] == 0)
            cnt--;
    }

    if (C == 2) {
        int L = *prev(u);
        u++;
        int R = *u;
        u--;
        diff[R - L]++;
        if (diff[R - L] == 1)
            cnt++;
    }
    other_sequence.erase(u);
}

int main() {
    fast;
    int N;
    cin >> N;

    h = vector<int>(N+1, 0);
    for (int i = 1; i <= N; i++)
        cin >> h[i];
    sort(h.begin(), h.end());

    if (N == 2) {
        cout << "1\n";
        cout << h[1] << "\n";
        cout << "1\n";
        cout << h[2] << "\n";
        exit(0);
    }

    for (int i = 1; i <= 2; i++) {
        for (int j = i+1; j <= 3; j++) {
            diff.clear();
            other_sequence.clear();
            sequence.clear();
            for (int q = 1; q <= N; q++) {
                other_sequence.insert(h[q]);
                if (q != 1)
                    diff[h[q] - h[q-1]]++;
            }
            cnt = diff.size();

            omit(h[i]);
            omit(h[j]);
            sequence.push_back(h[i]);
            sequence.push_back(h[j]);

            if (cnt <= 1) {
                if (other_sequence.size() == 0) {
                    other_sequence.insert(sequence.back());
                    sequence.pop_back();
                }

                cout << sequence.size() << "\n";
                for (auto u : sequence)
                    cout << u << " ";
                cout << "\n";
                cout << other_sequence.size() << "\n";
                for (auto u : other_sequence)
                    cout << u << " ";
                cout << "\n";
                exit(0);
            }

            int seq_diff = sequence[1] - sequence[0];
            while (true) {
                int potential_new = sequence.back() + seq_diff;
                if (other_sequence.count(potential_new) == 0)
                    break;

                omit(potential_new);
                sequence.push_back(potential_new);

                if (cnt <= 1) {
                    if (other_sequence.size() == 0) {
                        other_sequence.insert(sequence.back());
                        sequence.pop_back();
                    }

                    cout << sequence.size() << "\n";
                    for (auto u : sequence)
                        cout << u << " ";
                    cout << "\n";
                    cout << other_sequence.size() << "\n";
                    for (auto u : other_sequence)
                        cout << u << " ";
                    cout << "\n";
                    exit(0);
                }
            }
        }
    }
    cout << "-1\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 456 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 456 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 452 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 7888 KB Output is correct
2 Correct 37 ms 7252 KB Output is correct
3 Correct 41 ms 7632 KB Output is correct
4 Correct 36 ms 7508 KB Output is correct
5 Correct 69 ms 7984 KB Output is correct
6 Correct 37 ms 7508 KB Output is correct
7 Correct 58 ms 7908 KB Output is correct
8 Correct 41 ms 7352 KB Output is correct
9 Correct 38 ms 6664 KB Output is correct
10 Correct 39 ms 7504 KB Output is correct
11 Correct 30 ms 7508 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 456 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 452 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 58 ms 7888 KB Output is correct
32 Correct 37 ms 7252 KB Output is correct
33 Correct 41 ms 7632 KB Output is correct
34 Correct 36 ms 7508 KB Output is correct
35 Correct 69 ms 7984 KB Output is correct
36 Correct 37 ms 7508 KB Output is correct
37 Correct 58 ms 7908 KB Output is correct
38 Correct 41 ms 7352 KB Output is correct
39 Correct 38 ms 6664 KB Output is correct
40 Correct 39 ms 7504 KB Output is correct
41 Correct 30 ms 7508 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 55 ms 7764 KB Output is correct
44 Correct 105 ms 7000 KB Output is correct
45 Correct 37 ms 6696 KB Output is correct
46 Correct 39 ms 7508 KB Output is correct
47 Correct 73 ms 6740 KB Output is correct
48 Correct 35 ms 6860 KB Output is correct
49 Correct 58 ms 7768 KB Output is correct
50 Correct 54 ms 6480 KB Output is correct
51 Correct 34 ms 6964 KB Output is correct
52 Correct 40 ms 7508 KB Output is correct
53 Correct 70 ms 6740 KB Output is correct
54 Correct 35 ms 6800 KB Output is correct
55 Correct 41 ms 7508 KB Output is correct
56 Correct 50 ms 7508 KB Output is correct
57 Correct 31 ms 7508 KB Output is correct
58 Correct 0 ms 348 KB Output is correct