Submission #796769

# Submission time Handle Problem Language Result Execution time Memory
796769 2023-07-28T17:48:06 Z AbdullahMohammedAhmad Minerals (JOI19_minerals) C++14
90 / 100
59 ms 5728 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;
const int N = 1e5 + 69;
int in[N], added[N];
 
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);
        return;
    }
    int mid = (sz(b) < 2 ? sz(b) / 2 : min(sz(b) - 1, sz(b) / 2 + 2));
    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]);
    }
 
    vector<int> first_half, second_half;
    for(auto& x: a) {
        if(added[x]) continue;
        if(in[x] <= mid) {
            first_half.push_back(x);
            x = -1;
        }
        else added[x] = 1;
    }
 
    {
        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), swap(first_half, second_half);
    }
 
    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;
        }
    }
 
    shuffle(a.begin(), a.end(), rng);
    for(auto x: a) {
        if(x == -1) continue;
        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) {
    for(int i = 0; i < N; ++i) in[i] = INT_MAX;
    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);
            in[i] = ans;
        } 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;
    for(auto x: p1) b.push_back({x, 1});
    rec(p2, b);
}
/*
4
1 5
2 6
3 4
7 8
*/
// g++ -Wall -lm -static -DEVAL -o minerals -O2 minerals.cpp grader.cpp -std=c++17
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 1 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 720 KB Output is correct
2 Correct 3 ms 848 KB Output is correct
3 Correct 4 ms 1112 KB Output is correct
4 Correct 8 ms 1564 KB Output is correct
5 Correct 20 ms 2256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 1 ms 720 KB Output is correct
5 Correct 1 ms 720 KB Output is correct
6 Correct 3 ms 848 KB Output is correct
7 Correct 4 ms 1112 KB Output is correct
8 Correct 8 ms 1564 KB Output is correct
9 Correct 20 ms 2256 KB Output is correct
10 Correct 1 ms 720 KB Output is correct
11 Correct 12 ms 1872 KB Output is correct
12 Correct 21 ms 2356 KB Output is correct
13 Correct 16 ms 2384 KB Output is correct
14 Correct 16 ms 2256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 1 ms 720 KB Output is correct
5 Correct 1 ms 720 KB Output is correct
6 Correct 3 ms 848 KB Output is correct
7 Correct 4 ms 1112 KB Output is correct
8 Correct 8 ms 1564 KB Output is correct
9 Correct 20 ms 2256 KB Output is correct
10 Correct 1 ms 720 KB Output is correct
11 Correct 12 ms 1872 KB Output is correct
12 Correct 21 ms 2356 KB Output is correct
13 Correct 16 ms 2384 KB Output is correct
14 Correct 16 ms 2256 KB Output is correct
15 Correct 45 ms 5212 KB Output is correct
16 Correct 45 ms 5136 KB Output is correct
17 Correct 49 ms 5072 KB Output is correct
18 Correct 49 ms 5048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 1 ms 720 KB Output is correct
5 Correct 1 ms 720 KB Output is correct
6 Correct 3 ms 848 KB Output is correct
7 Correct 4 ms 1112 KB Output is correct
8 Correct 8 ms 1564 KB Output is correct
9 Correct 20 ms 2256 KB Output is correct
10 Correct 1 ms 720 KB Output is correct
11 Correct 12 ms 1872 KB Output is correct
12 Correct 21 ms 2356 KB Output is correct
13 Correct 16 ms 2384 KB Output is correct
14 Correct 16 ms 2256 KB Output is correct
15 Correct 45 ms 5212 KB Output is correct
16 Correct 45 ms 5136 KB Output is correct
17 Correct 49 ms 5072 KB Output is correct
18 Correct 49 ms 5048 KB Output is correct
19 Correct 51 ms 5220 KB Output is correct
20 Correct 46 ms 5336 KB Output is correct
21 Correct 46 ms 5316 KB Output is correct
22 Correct 53 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 1 ms 720 KB Output is correct
5 Correct 1 ms 720 KB Output is correct
6 Correct 3 ms 848 KB Output is correct
7 Correct 4 ms 1112 KB Output is correct
8 Correct 8 ms 1564 KB Output is correct
9 Correct 20 ms 2256 KB Output is correct
10 Correct 1 ms 720 KB Output is correct
11 Correct 12 ms 1872 KB Output is correct
12 Correct 21 ms 2356 KB Output is correct
13 Correct 16 ms 2384 KB Output is correct
14 Correct 16 ms 2256 KB Output is correct
15 Correct 45 ms 5212 KB Output is correct
16 Correct 45 ms 5136 KB Output is correct
17 Correct 49 ms 5072 KB Output is correct
18 Correct 49 ms 5048 KB Output is correct
19 Correct 51 ms 5220 KB Output is correct
20 Correct 46 ms 5336 KB Output is correct
21 Correct 46 ms 5316 KB Output is correct
22 Correct 53 ms 5112 KB Output is correct
23 Correct 48 ms 5356 KB Output is correct
24 Correct 48 ms 5464 KB Output is correct
25 Correct 52 ms 5568 KB Output is correct
26 Correct 48 ms 5280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 1 ms 720 KB Output is correct
5 Correct 1 ms 720 KB Output is correct
6 Correct 3 ms 848 KB Output is correct
7 Correct 4 ms 1112 KB Output is correct
8 Correct 8 ms 1564 KB Output is correct
9 Correct 20 ms 2256 KB Output is correct
10 Correct 1 ms 720 KB Output is correct
11 Correct 12 ms 1872 KB Output is correct
12 Correct 21 ms 2356 KB Output is correct
13 Correct 16 ms 2384 KB Output is correct
14 Correct 16 ms 2256 KB Output is correct
15 Correct 45 ms 5212 KB Output is correct
16 Correct 45 ms 5136 KB Output is correct
17 Correct 49 ms 5072 KB Output is correct
18 Correct 49 ms 5048 KB Output is correct
19 Correct 51 ms 5220 KB Output is correct
20 Correct 46 ms 5336 KB Output is correct
21 Correct 46 ms 5316 KB Output is correct
22 Correct 53 ms 5112 KB Output is correct
23 Correct 48 ms 5356 KB Output is correct
24 Correct 48 ms 5464 KB Output is correct
25 Correct 52 ms 5568 KB Output is correct
26 Correct 48 ms 5280 KB Output is correct
27 Correct 49 ms 5448 KB Output is correct
28 Correct 51 ms 5488 KB Output is correct
29 Correct 48 ms 5448 KB Output is correct
30 Correct 53 ms 5320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 1 ms 720 KB Output is correct
5 Correct 1 ms 720 KB Output is correct
6 Correct 3 ms 848 KB Output is correct
7 Correct 4 ms 1112 KB Output is correct
8 Correct 8 ms 1564 KB Output is correct
9 Correct 20 ms 2256 KB Output is correct
10 Correct 1 ms 720 KB Output is correct
11 Correct 12 ms 1872 KB Output is correct
12 Correct 21 ms 2356 KB Output is correct
13 Correct 16 ms 2384 KB Output is correct
14 Correct 16 ms 2256 KB Output is correct
15 Correct 45 ms 5212 KB Output is correct
16 Correct 45 ms 5136 KB Output is correct
17 Correct 49 ms 5072 KB Output is correct
18 Correct 49 ms 5048 KB Output is correct
19 Correct 51 ms 5220 KB Output is correct
20 Correct 46 ms 5336 KB Output is correct
21 Correct 46 ms 5316 KB Output is correct
22 Correct 53 ms 5112 KB Output is correct
23 Correct 48 ms 5356 KB Output is correct
24 Correct 48 ms 5464 KB Output is correct
25 Correct 52 ms 5568 KB Output is correct
26 Correct 48 ms 5280 KB Output is correct
27 Correct 49 ms 5448 KB Output is correct
28 Correct 51 ms 5488 KB Output is correct
29 Correct 48 ms 5448 KB Output is correct
30 Correct 53 ms 5320 KB Output is correct
31 Correct 55 ms 5728 KB Output is correct
32 Correct 53 ms 5608 KB Output is correct
33 Correct 50 ms 5580 KB Output is correct
34 Correct 59 ms 5556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 1 ms 720 KB Output is correct
5 Correct 1 ms 720 KB Output is correct
6 Correct 3 ms 848 KB Output is correct
7 Correct 4 ms 1112 KB Output is correct
8 Correct 8 ms 1564 KB Output is correct
9 Correct 20 ms 2256 KB Output is correct
10 Correct 1 ms 720 KB Output is correct
11 Correct 12 ms 1872 KB Output is correct
12 Correct 21 ms 2356 KB Output is correct
13 Correct 16 ms 2384 KB Output is correct
14 Correct 16 ms 2256 KB Output is correct
15 Correct 45 ms 5212 KB Output is correct
16 Correct 45 ms 5136 KB Output is correct
17 Correct 49 ms 5072 KB Output is correct
18 Correct 49 ms 5048 KB Output is correct
19 Correct 51 ms 5220 KB Output is correct
20 Correct 46 ms 5336 KB Output is correct
21 Correct 46 ms 5316 KB Output is correct
22 Correct 53 ms 5112 KB Output is correct
23 Correct 48 ms 5356 KB Output is correct
24 Correct 48 ms 5464 KB Output is correct
25 Correct 52 ms 5568 KB Output is correct
26 Correct 48 ms 5280 KB Output is correct
27 Correct 49 ms 5448 KB Output is correct
28 Correct 51 ms 5488 KB Output is correct
29 Correct 48 ms 5448 KB Output is correct
30 Correct 53 ms 5320 KB Output is correct
31 Correct 55 ms 5728 KB Output is correct
32 Correct 53 ms 5608 KB Output is correct
33 Correct 50 ms 5580 KB Output is correct
34 Correct 59 ms 5556 KB Output is correct
35 Incorrect 51 ms 5576 KB Wrong Answer [2]
36 Halted 0 ms 0 KB -