이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
for(int i = 1; i <= N; i++) A.insert(i);
for(int i = N+1; i <= 2*N; i++) 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);
}
}
컴파일 시 표준 에러 (stderr) 메시지
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |