QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#812082 | #9156. 百万富翁 | dvbs2000 | 15 | 618ms | 20608kb | C++14 | 1.4kb | 2024-12-13 11:23:02 | 2024-12-13 11:23:04 |
Judging History
answer
#include "richest.h"
#include <vector>
// Declaration of the ask function as specified
std::vector<int> ask(std::vector<int> a, std::vector<int> b);
// Function to find the richest customer
int richest(int N, int T, int S) {
// Edge case: Only one customer
if (N == 1) {
return 0;
}
// Prepare all possible pairs (i, j) where i < j
std::vector<int> a;
std::vector<int> b;
a.reserve((N * (N - 1)) / 2);
b.reserve((N * (N - 1)) / 2);
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) {
a.push_back(i);
b.push_back(j);
}
}
// Ensure that we do not exceed the query limit
// Since S is guaranteed to be at least (N*(N-1))/2 for test cases,
// we do not need additional checks here.
// Make a single request with all pairs
std::vector<int> responses = ask(a, b);
// Count the number of times each customer wins
std::vector<int> win_counts(N, 0);
for (const int& winner : responses) {
// Increment the win count for the winning customer
++win_counts[winner];
}
// Find the customer with the maximum win count
int richest_customer = 0;
int max_wins = win_counts[0];
for (int i = 1; i < N; ++i) {
if (win_counts[i] > max_wins) {
max_wins = win_counts[i];
richest_customer = i;
}
}
return richest_customer;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Pretest #1:
score: 15
Accepted
time: 618ms
memory: 20608kb
input:
1000 1 499500 957319859
output:
Correct 7127326332295218295 1.000000 1331569654267968081
result:
points 1.0 Correct
Pretest #2:
score: 0
Runtime Error
input:
1000000 20 2000000 29091473
output:
Unauthorized output
result:
Final Tests
Test #1:
score: 15
Accepted
time: 609ms
memory: 20544kb
input:
1000 1 499500 957319857
output:
Correct 7127326332295218295 1.000000 1331569654267968081
result:
points 1.0 Correct
Test #2:
score: 0
Runtime Error
input:
1000000 20 2000000 29091471
output:
Unauthorized output