Submission #1164433

#TimeUsernameProblemLanguageResultExecution timeMemory
1164433nguyentunglamPassword (RMI18_password)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;

const int N = 5010;
int cnt[N];
char a[N], b[N];

int query(string q);

string guess (int n, int s) {
    string answer;
    vector<int> initCnt(s);
    for (int j = 0; j < s; j++) {
      char c = 'a' + j;
      string ask;
      for (int i = 0; i < n; i++) {
        ask.push_back(c);
      }
      initCnt[j] = query(ask);
    }
    vector<int> missingLeftCnt(s), missingRightCnt(s);
    auto solve = [&] (auto solve, vector<int> cnt) -> string {
      string ret;
      int sum = 0;
      for (int i = 0; i < s; i++) {
        sum += cnt[i];
      }
      if (sum == 0) return ret;
      int randomValue = random(1, sum);
      vector<int> leftCnt(s), rightCnt(s);
      pair<int, int> pivot;
      for (int i = 0; i < s; i++) {
        if (randomValue <= cnt[i]) {
          pivot = {i, randomValue};
          break;
        }
        randomValue -= cnt[i];
      }
      leftCnt[pivot.first] = pivot.second - 1;
      rightCnt[pivot.first] = cnt[pivot.first] - pivot.second;
      string ask;
      for (int i = 0; i < pivot.second + missingLeftCnt[pivot.first]; i++) {
        ask.push_back('a' + pivot.first);
      }
      for (int i = 0; i < s; i++) if (cnt[i]) {
        if (i == pivot.first) continue;
        string _ask = ask;
        for (int j = 0; j < cnt[i] + missingRightCnt[i]; j++) {
          _ask.push_back('a' + i);
        }
        rightCnt[i] = max(0, query(_ask) - pivot.second - missingLeftCnt[pivot.first] - missingRightCnt[i]);
        leftCnt[i] = cnt[i] - rightCnt[i];
      }
      for (int i = 0; i < s; i++) missingRightCnt[i] += rightCnt[i];
      missingRightCnt[pivot.first]++;
      string leftString = solve(solve, leftCnt);
      for (int i = 0; i < s; i++) missingRightCnt[i] -= rightCnt[i];
      missingRightCnt[pivot.first]--;
      for (int i = 0; i < s; i++) missingLeftCnt[i] += leftCnt[i];
      missingLeftCnt[pivot.first]++;
      string rightString = solve(solve, rightCnt);
      for (int i = 0; i < s; i++) missingLeftCnt[i] -= leftCnt[i];
      missingLeftCnt[pivot.first]--;
      string middle;
      middle.push_back('a' + pivot.first);
      ret = leftString + middle + rightString;
      return ret;
    };
  
    return solve(solve, initCnt);
}

Compilation message (stderr)

password.cpp: In lambda function:
password.cpp:29:31: error: too many arguments to function 'long int random()'
   29 |       int randomValue = random(1, sum);
      |                         ~~~~~~^~~~~~~~
In file included from /usr/include/c++/11/bits/std_abs.h:38,
                 from /usr/include/c++/11/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from password.cpp:1:
/usr/include/stdlib.h:402:17: note: declared here
  402 | extern long int random (void) __THROW;
      |                 ^~~~~~
password.cpp: In instantiation of 'guess(int, int)::<lambda(auto:23, std::vector<int>)> [with auto:23 = guess(int, int)::<lambda(auto:23, std::vector<int>)>; std::string = std::__cxx11::basic_string<char>]':
password.cpp:70:17:   required from here
password.cpp:29:31: error: too many arguments to function 'long int random()'
   29 |       int randomValue = random(1, sum);
      |                         ~~~~~~^~~~~~~~
In file included from /usr/include/c++/11/bits/std_abs.h:38,
                 from /usr/include/c++/11/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from password.cpp:1:
/usr/include/stdlib.h:402:17: note: declared here
  402 | extern long int random (void) __THROW;
      |                 ^~~~~~