답안 #796621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
796621 2023-07-28T14:53:29 Z SlavicG Minerals (JOI19_minerals) C++17
90 / 100
65 ms 6856 KB
#include <bits/stdc++.h>
#include "minerals.h"
using namespace std;
 
#define sz(a) (int)a.size()
mt19937 rng(69);
//b - valoarea elementului, stateul (aprins/stins)
int ans = 0, prevans = -1;
map<int, int> paired;
void rec(vector<int> a, vector<pair<int, int>> b) {
    if(b.empty() || a.empty()) return;
    if(sz(b) == 1) {
        for(auto x: a) Answer(x, b[0].first), paired[b[0].first] = 1;
        return;
    }
    int mid = (sz(b) <= 20 ? sz(b) / 2 : sz(b) / 2 - rng() % 6);
    vector<pair<int, int>> left, right;
    for(int i = 0; i < sz(b); ++i) {
        if(i < mid) left.push_back(b[i]);
        else right.push_back(b[i]);
    }

    {
        int change1 = 0, change2 = 0;
        for(auto& x: left) {
            if(!x.second) {
                ++change1;
            } else {
                ++change2;
            }
        }
        for(auto& x: right) {
            if(x.second) {
                ++change1;
            } else {
                ++change2;
            }
        }
        if(change2 < change1) swap(left, right);
    }

    for(auto& x: left) {
        if(!x.second) {
            prevans = Query(x.first);
            x.second = 1;
        }
    }
    for(auto& x: right) {
        if(x.second) {
            prevans = Query(x.first);
            x.second = 0;
        }
    }

    vector<int> first_half, second_half;
    for(auto x: a) {
        if(sz(second_half) >= sz(right)) {
            first_half.push_back(x);
            continue;
        }
        if(sz(first_half) >= sz(left)) {
            second_half.push_back(x);
            continue;
        }
        int ans = Query(x);
        if(ans == prevans) {
            first_half.push_back(x);
        } else {
            second_half.push_back(x);
        }
        prevans = ans;
    }
    rec(second_half, right);
    rec(first_half, left);
}
void Solve(int n) {
    vector<int> p1, p2;
    vector<int> bulanea(2 * n);
    iota(bulanea.begin(), bulanea.end(), 1);
    shuffle(bulanea.begin(), bulanea.end(), rng);
    for(int i: bulanea) {
        ans = Query(i);
        if(ans == prevans) {
            p2.push_back(i);
        } else {
            p1.push_back(i);
        }
        prevans = ans;
        if(sz(p1) == n) {
            for(int j = 0; j < sz(bulanea); ++j) {
                if(bulanea[j] == i) {
                    for(int f = j + 1; f < sz(bulanea); ++f) {
                        p2.push_back(bulanea[f]);
                    }
                    break;
                }
            }
            break;
        }
    }
    assert(sz(p1) == n && sz(p2) == n);
    vector<pair<int, int>> b;
    int paiu = p2.back();
    p2.pop_back();
    for(auto x: p1) b.push_back({x, 1});
    rec(p2, b);
    for(auto x: p1) {
        if(!paired[x]) {
            Answer(paiu, x);
        }
    }
}
/*
4
1 5
2 6
3 4
7 8
*/
// g++ -Wall -lm -static -DEVAL -o minerals -O2 minerals.cpp grader.cpp -std=c++17
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 4 ms 924 KB Output is correct
4 Correct 9 ms 1504 KB Output is correct
5 Correct 17 ms 2512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 4 ms 924 KB Output is correct
8 Correct 9 ms 1504 KB Output is correct
9 Correct 17 ms 2512 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 12 ms 1872 KB Output is correct
12 Correct 21 ms 2584 KB Output is correct
13 Correct 17 ms 2512 KB Output is correct
14 Correct 17 ms 2512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 4 ms 924 KB Output is correct
8 Correct 9 ms 1504 KB Output is correct
9 Correct 17 ms 2512 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 12 ms 1872 KB Output is correct
12 Correct 21 ms 2584 KB Output is correct
13 Correct 17 ms 2512 KB Output is correct
14 Correct 17 ms 2512 KB Output is correct
15 Correct 50 ms 6128 KB Output is correct
16 Correct 51 ms 6216 KB Output is correct
17 Correct 49 ms 6116 KB Output is correct
18 Correct 53 ms 5948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 4 ms 924 KB Output is correct
8 Correct 9 ms 1504 KB Output is correct
9 Correct 17 ms 2512 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 12 ms 1872 KB Output is correct
12 Correct 21 ms 2584 KB Output is correct
13 Correct 17 ms 2512 KB Output is correct
14 Correct 17 ms 2512 KB Output is correct
15 Correct 50 ms 6128 KB Output is correct
16 Correct 51 ms 6216 KB Output is correct
17 Correct 49 ms 6116 KB Output is correct
18 Correct 53 ms 5948 KB Output is correct
19 Correct 52 ms 6356 KB Output is correct
20 Correct 51 ms 6276 KB Output is correct
21 Correct 51 ms 6316 KB Output is correct
22 Correct 50 ms 6192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 4 ms 924 KB Output is correct
8 Correct 9 ms 1504 KB Output is correct
9 Correct 17 ms 2512 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 12 ms 1872 KB Output is correct
12 Correct 21 ms 2584 KB Output is correct
13 Correct 17 ms 2512 KB Output is correct
14 Correct 17 ms 2512 KB Output is correct
15 Correct 50 ms 6128 KB Output is correct
16 Correct 51 ms 6216 KB Output is correct
17 Correct 49 ms 6116 KB Output is correct
18 Correct 53 ms 5948 KB Output is correct
19 Correct 52 ms 6356 KB Output is correct
20 Correct 51 ms 6276 KB Output is correct
21 Correct 51 ms 6316 KB Output is correct
22 Correct 50 ms 6192 KB Output is correct
23 Correct 52 ms 6544 KB Output is correct
24 Correct 53 ms 6452 KB Output is correct
25 Correct 65 ms 6548 KB Output is correct
26 Correct 52 ms 6288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 4 ms 924 KB Output is correct
8 Correct 9 ms 1504 KB Output is correct
9 Correct 17 ms 2512 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 12 ms 1872 KB Output is correct
12 Correct 21 ms 2584 KB Output is correct
13 Correct 17 ms 2512 KB Output is correct
14 Correct 17 ms 2512 KB Output is correct
15 Correct 50 ms 6128 KB Output is correct
16 Correct 51 ms 6216 KB Output is correct
17 Correct 49 ms 6116 KB Output is correct
18 Correct 53 ms 5948 KB Output is correct
19 Correct 52 ms 6356 KB Output is correct
20 Correct 51 ms 6276 KB Output is correct
21 Correct 51 ms 6316 KB Output is correct
22 Correct 50 ms 6192 KB Output is correct
23 Correct 52 ms 6544 KB Output is correct
24 Correct 53 ms 6452 KB Output is correct
25 Correct 65 ms 6548 KB Output is correct
26 Correct 52 ms 6288 KB Output is correct
27 Correct 53 ms 6640 KB Output is correct
28 Correct 54 ms 6716 KB Output is correct
29 Correct 55 ms 6680 KB Output is correct
30 Correct 54 ms 6556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 4 ms 924 KB Output is correct
8 Correct 9 ms 1504 KB Output is correct
9 Correct 17 ms 2512 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 12 ms 1872 KB Output is correct
12 Correct 21 ms 2584 KB Output is correct
13 Correct 17 ms 2512 KB Output is correct
14 Correct 17 ms 2512 KB Output is correct
15 Correct 50 ms 6128 KB Output is correct
16 Correct 51 ms 6216 KB Output is correct
17 Correct 49 ms 6116 KB Output is correct
18 Correct 53 ms 5948 KB Output is correct
19 Correct 52 ms 6356 KB Output is correct
20 Correct 51 ms 6276 KB Output is correct
21 Correct 51 ms 6316 KB Output is correct
22 Correct 50 ms 6192 KB Output is correct
23 Correct 52 ms 6544 KB Output is correct
24 Correct 53 ms 6452 KB Output is correct
25 Correct 65 ms 6548 KB Output is correct
26 Correct 52 ms 6288 KB Output is correct
27 Correct 53 ms 6640 KB Output is correct
28 Correct 54 ms 6716 KB Output is correct
29 Correct 55 ms 6680 KB Output is correct
30 Correct 54 ms 6556 KB Output is correct
31 Correct 58 ms 6852 KB Output is correct
32 Correct 55 ms 6856 KB Output is correct
33 Correct 61 ms 6808 KB Output is correct
34 Correct 55 ms 6648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 4 ms 924 KB Output is correct
8 Correct 9 ms 1504 KB Output is correct
9 Correct 17 ms 2512 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 12 ms 1872 KB Output is correct
12 Correct 21 ms 2584 KB Output is correct
13 Correct 17 ms 2512 KB Output is correct
14 Correct 17 ms 2512 KB Output is correct
15 Correct 50 ms 6128 KB Output is correct
16 Correct 51 ms 6216 KB Output is correct
17 Correct 49 ms 6116 KB Output is correct
18 Correct 53 ms 5948 KB Output is correct
19 Correct 52 ms 6356 KB Output is correct
20 Correct 51 ms 6276 KB Output is correct
21 Correct 51 ms 6316 KB Output is correct
22 Correct 50 ms 6192 KB Output is correct
23 Correct 52 ms 6544 KB Output is correct
24 Correct 53 ms 6452 KB Output is correct
25 Correct 65 ms 6548 KB Output is correct
26 Correct 52 ms 6288 KB Output is correct
27 Correct 53 ms 6640 KB Output is correct
28 Correct 54 ms 6716 KB Output is correct
29 Correct 55 ms 6680 KB Output is correct
30 Correct 54 ms 6556 KB Output is correct
31 Correct 58 ms 6852 KB Output is correct
32 Correct 55 ms 6856 KB Output is correct
33 Correct 61 ms 6808 KB Output is correct
34 Correct 55 ms 6648 KB Output is correct
35 Incorrect 50 ms 6812 KB Wrong Answer [2]
36 Halted 0 ms 0 KB -