QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#812060 | #9156. 百万富翁 | dvbs2000 | 11.00002 | 2405ms | 99208kb | C++14 | 2.4kb | 2024-12-13 11:09:33 | 2024-12-13 11:09:40 |
Judging History
answer
#include <vector>
// Declaration of the ask function provided by the interactor.
std::vector<int> ask(std::vector<int> a, std::vector<int> b);
int richest(int N, int T, int S) {
if (N == 1) {
// If there's only one customer, they are the richest by default.
return 0;
}
// Initialize the list of candidates with all customer indices.
std::vector<int> candidates;
candidates.reserve(N);
for(int i = 0; i < N; ++i){
candidates.push_back(i);
}
// Variables to keep track of the number of requests and total queries used.
int t_used = 0;
int s_used = 0;
// Temporary vectors to store the next round of candidates.
std::vector<int> next_candidates;
next_candidates.reserve(N / 2 + 1);
while(candidates.size() > 1){
next_candidates.clear();
std::vector<int> a;
std::vector<int> b;
a.reserve(candidates.size() / 2);
b.reserve(candidates.size() / 2);
// Pair up the candidates.
int i = 0;
for(; i + 1 < candidates.size(); i += 2){
a.push_back(candidates[i]);
b.push_back(candidates[i + 1]);
}
// If there's an odd number of candidates, carry the last one to the next round.
bool has_carry_over = false;
int carry_over = -1;
if(i < candidates.size()){
has_carry_over = true;
carry_over = candidates[i];
}
// Update the counts for requests and queries.
t_used += 1;
s_used += a.size();
// Make sure we do not exceed the limits.
if(t_used > T || s_used > S){
// If limits are exceeded, return an invalid index (could also handle differently).
return -1;
}
// Send the current batch of comparisons to the interactor.
std::vector<int> winners = ask(a, b);
// Add the winners to the next round's candidate list.
for(auto &winner : winners){
next_candidates.push_back(winner);
}
// If there was a carry-over, add it to the next round.
if(has_carry_over){
next_candidates.push_back(carry_over);
}
// Swap the candidate lists for the next iteration.
candidates.swap(next_candidates);
}
// The last remaining candidate is the richest.
return candidates[0];
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Pretest #1:
score: 0
Wrong Answer
time: 1ms
memory: 7968kb
input:
1000 1 499500 957319859
output:
Wrong answer 4459638610240858557 0.000000 6906350380861515327
result:
points 0.0 Wrong answer
Pretest #2:
score: 11
Acceptable Answer
time: 2399ms
memory: 99208kb
input:
1000000 20 2000000 29091473
output:
Partially correct Case 2, 11 / 85, maxt = 20, maxs = 999999 1811468636458994965 0.129412 3823502568050958645
result:
points 0.129412 Partially correct Case 2, 11 / 85, maxt = 20, maxs = 999999
Final Tests
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 10068kb
input:
1000 1 499500 957319857
output:
Wrong answer 4459638610240858557 0.000000 6906350380861515327
result:
points 0.0 Wrong answer
Test #2:
score: 11
Acceptable Answer
time: 2405ms
memory: 93956kb
input:
1000000 20 2000000 29091471
output:
Partially correct Case 2, 11 / 85, maxt = 20, maxs = 999999 1811468636458994965 0.129412 3823502568050958645
result:
points 0.129412 Partially correct Case 2, 11 / 85, maxt = 20, maxs = 999999