Submission #1117313

#TimeUsernameProblemLanguageResultExecution timeMemory
1117313plescagheorghe07Password (RMI18_password)C++14
0 / 100
2 ms336 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...