Submission #836088

# Submission time Handle Problem Language Result Execution time Memory
836088 2023-08-24T07:13:57 Z _martynas Minerals (JOI19_minerals) C++14
40 / 100
142 ms 21360 KB
#include "minerals.h"
#include <bits/stdc++.h>

using namespace std;

set<int> in;
map<int, int> M;

/*
solve(A, B)
A -> C D
B -> E F
solve(C, E), solve(D, F)
*/
void solve(set<int> A, set<int> B) {
    assert(A.size() == B.size());
    if(A.empty()) return;
    if(A.size() == 1) {
        M[*A.begin()] = *B.begin();
        return;
    }
    if(!in.empty()) {
        // todo: optimize to not take out needed minerals
        for(int x : in) Query(x);
        in.clear();
    }
    auto ita = A.begin();
    set<int> C, D, E, F;
    int resp;
    int split = A.size()/2;
    for(int i = 0; i < split; i++) {
        C.insert(*ita); in.insert(*ita);
        resp = Query(*ita);
        ita = next(ita);
    }
    assert(resp == C.size());
    while(ita != A.end()) D.insert(*ita), ita = next(ita);
    for(int b : B) {
        int nresp = Query(b); in.insert(b);
        if(nresp != resp) {
            F.insert(b);
            resp = nresp;
        }
        else {
            E.insert(b);
        }
    }
    solve(C, E), solve(D, F);
}

void Solve(int N) {
    // sub2: all 1, 2, ..., N are in the first half and in the second half
    set<int> A, B;
    int resp = -1, nresp;
    for(int i = 1; i <= 2*N; i++) {
        nresp = Query(i);
        in.insert(i);
        if(resp != nresp) {
            A.insert(i);
            resp = nresp;
        }
        else {
            B.insert(i);
        }
    }
    solve(A, B);
    // for(auto p : M) {
    //     cout << p.first << " " << p.second << "\n";
    // }
    for(auto p : M) {
        Answer(p.first, p.second);
    }
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from minerals.cpp:2:
minerals.cpp: In function 'void solve(std::set<int>, std::set<int>)':
minerals.cpp:36:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     assert(resp == C.size());
      |            ~~~~~^~~~~~~~~~~
minerals.cpp:36:12: warning: 'resp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   36 |     assert(resp == C.size());
      |            ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 848 KB Output is correct
2 Correct 10 ms 1488 KB Output is correct
3 Correct 17 ms 2796 KB Output is correct
4 Correct 39 ms 5284 KB Output is correct
5 Correct 83 ms 9792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 4 ms 848 KB Output is correct
6 Correct 10 ms 1488 KB Output is correct
7 Correct 17 ms 2796 KB Output is correct
8 Correct 39 ms 5284 KB Output is correct
9 Correct 83 ms 9792 KB Output is correct
10 Correct 4 ms 848 KB Output is correct
11 Correct 53 ms 6680 KB Output is correct
12 Correct 82 ms 9916 KB Output is correct
13 Correct 72 ms 9800 KB Output is correct
14 Correct 83 ms 9788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 4 ms 848 KB Output is correct
6 Correct 10 ms 1488 KB Output is correct
7 Correct 17 ms 2796 KB Output is correct
8 Correct 39 ms 5284 KB Output is correct
9 Correct 83 ms 9792 KB Output is correct
10 Correct 4 ms 848 KB Output is correct
11 Correct 53 ms 6680 KB Output is correct
12 Correct 82 ms 9916 KB Output is correct
13 Correct 72 ms 9800 KB Output is correct
14 Correct 83 ms 9788 KB Output is correct
15 Incorrect 142 ms 21360 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 4 ms 848 KB Output is correct
6 Correct 10 ms 1488 KB Output is correct
7 Correct 17 ms 2796 KB Output is correct
8 Correct 39 ms 5284 KB Output is correct
9 Correct 83 ms 9792 KB Output is correct
10 Correct 4 ms 848 KB Output is correct
11 Correct 53 ms 6680 KB Output is correct
12 Correct 82 ms 9916 KB Output is correct
13 Correct 72 ms 9800 KB Output is correct
14 Correct 83 ms 9788 KB Output is correct
15 Incorrect 142 ms 21360 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 4 ms 848 KB Output is correct
6 Correct 10 ms 1488 KB Output is correct
7 Correct 17 ms 2796 KB Output is correct
8 Correct 39 ms 5284 KB Output is correct
9 Correct 83 ms 9792 KB Output is correct
10 Correct 4 ms 848 KB Output is correct
11 Correct 53 ms 6680 KB Output is correct
12 Correct 82 ms 9916 KB Output is correct
13 Correct 72 ms 9800 KB Output is correct
14 Correct 83 ms 9788 KB Output is correct
15 Incorrect 142 ms 21360 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 4 ms 848 KB Output is correct
6 Correct 10 ms 1488 KB Output is correct
7 Correct 17 ms 2796 KB Output is correct
8 Correct 39 ms 5284 KB Output is correct
9 Correct 83 ms 9792 KB Output is correct
10 Correct 4 ms 848 KB Output is correct
11 Correct 53 ms 6680 KB Output is correct
12 Correct 82 ms 9916 KB Output is correct
13 Correct 72 ms 9800 KB Output is correct
14 Correct 83 ms 9788 KB Output is correct
15 Incorrect 142 ms 21360 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 4 ms 848 KB Output is correct
6 Correct 10 ms 1488 KB Output is correct
7 Correct 17 ms 2796 KB Output is correct
8 Correct 39 ms 5284 KB Output is correct
9 Correct 83 ms 9792 KB Output is correct
10 Correct 4 ms 848 KB Output is correct
11 Correct 53 ms 6680 KB Output is correct
12 Correct 82 ms 9916 KB Output is correct
13 Correct 72 ms 9800 KB Output is correct
14 Correct 83 ms 9788 KB Output is correct
15 Incorrect 142 ms 21360 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 4 ms 848 KB Output is correct
6 Correct 10 ms 1488 KB Output is correct
7 Correct 17 ms 2796 KB Output is correct
8 Correct 39 ms 5284 KB Output is correct
9 Correct 83 ms 9792 KB Output is correct
10 Correct 4 ms 848 KB Output is correct
11 Correct 53 ms 6680 KB Output is correct
12 Correct 82 ms 9916 KB Output is correct
13 Correct 72 ms 9800 KB Output is correct
14 Correct 83 ms 9788 KB Output is correct
15 Incorrect 142 ms 21360 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -