이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |