This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <unistd.h>
#include <fstream>
using namespace std;
int query( string s );
string guess(int n, int s) {
string chars = "";
string result = "";
// Generate the set of characters to test
for (int i = 0; i < s; ++i)
chars += char('a' + i);
int last_match = 0;
while (static_cast<int>(result.size()) < n) { // Fix signed/unsigned warning
size_t low = 0, high = chars.size() - 1;
char found_char = '\0';
// Binary search to find the next character
while (low <= high) {
size_t mid = low + (high - low) / 2;
string temp = result + chars[mid];
int curr_match = query(temp);
if (curr_match > last_match) {
found_char = chars[mid];
last_match = curr_match;
break; // Exit binary search as we found the next character
}
if (curr_match < last_match) {
high = mid - 1;
} else {
low = mid + 1;
}
}
if (found_char != '\0') {
result += found_char;
} else {
cerr << "Failed to identify the next character!" << endl;
break;
}
}
return result;
}
# | 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... |