Submission #1118507

# Submission time Handle Problem Language Result Execution time Memory
1118507 2024-11-25T15:23:45 Z somefolk Password (RMI18_password) C++14
Compilation error
0 ms 0 KB
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <complex>
#include <list>
#include <chrono>
#include <random>
#include <stack>
#include <iomanip>
#include <fstream>
using namespace std;

#define endl "\n"
// #define int long long

const int INF = 2 * 1e5 + 5;
const int MOD = 1e9 + 7;

int query(string s);

// int query(string s);

string guess(int n, int s){
    bool pass = false;
    string sol = "";
    for(char i = 'a'; i < 'a'+s; i++){
        string letter = string(n, i);
        int amount = query(letter);
        int initAmount = amount;
        if(amount == 0) continue;
        if(!pass){
            sol += string(amount, i);
            pass = true;
        } else {
            int len = sol.length();
            vector<pair<int, int>> add;
            for(int j = 0; j <= len; j++){
                string curr = sol.substr(0, len-j) + string(n-(len-j), i);
                amount = query(curr);
                int pos = len - j;
                int diff = amount - pos;
                if(diff > 0){
                    add.push_back({pos, diff});
                    initAmount -= diff;
                    if(initAmount <= 0) break;
                }
            }
            int k = 0;
            for(auto &j : add){
                sol.insert(j.first + k, string(j.second, i));
                k+=j.second;
                // cout << "{" << j.first << " " << j.second << "}" << endl;
            }
            // cout << "| " << temp << " |" << endl;
        }
    }
    assert(sol.size()==n);
    return sol;
}

Compilation message

password.cpp: In function 'std::string guess(int, int)':
password.cpp:64:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |     assert(sol.size()==n);
      |            ~~~~~~~~~~^~~
password.cpp:64:5: error: 'assert' was not declared in this scope
   64 |     assert(sol.size()==n);
      |     ^~~~~~
password.cpp:18:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
   17 | #include <fstream>
  +++ |+#include <cassert>
   18 | using namespace std;