Submission #773335

#TimeUsernameProblemLanguageResultExecution timeMemory
773335aykhnPassword (RMI18_password)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> // author: aykhn using namespace std; typedef long long ll; int cnt[30]; priority_queue<pair<int, string>, vector<pair<int, string>>, greater<pair<int, string>>> pq; int query(string str); void MERGE(string &a, string &b) { int prev = query(b); for (int j = 0; j < b.length(); j++) { string tmp = b; b.ins(b.begin() + j, a[i]); int x = query(b); if (x <= prev) b = tmp; else i++; } } string guess(int n, int s) { string tmp = ""; for (int i = 0; i < n; i++) { tmp.pb('a'); } int prev = 0; for (int i = 0; i < s; i++) { cnt[i] = query(temp); pq.push(cnt[i], temp.substr(0, cnt[i])); for (int j = 0; j < n; j++) tmp[j]++; } while (pq.size() > 1) { string a = pq.top().se; pq.pop(); string b = pq.top().se; pq.pop(); MERGE(a, b); pq.push(mpr(b.length(), b)); } return pq.top(); }

Compilation message (stderr)

password.cpp: In function 'void MERGE(std::string&, std::string&)':
password.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int j = 0; j < b.length(); j++)
      |                     ~~^~~~~~~~~~~~
password.cpp:21:11: error: 'std::string' {aka 'class std::__cxx11::basic_string<char>'} has no member named 'ins'
   21 |         b.ins(b.begin() + j, a[i]);
      |           ^~~
password.cpp:21:32: error: 'i' was not declared in this scope
   21 |         b.ins(b.begin() + j, a[i]);
      |                                ^
password.cpp: In function 'std::string guess(int, int)':
password.cpp:33:13: error: 'std::string' {aka 'class std::__cxx11::basic_string<char>'} has no member named 'pb'
   33 |         tmp.pb('a');
      |             ^~
password.cpp:39:24: error: 'temp' was not declared in this scope; did you mean 'tmp'?
   39 |         cnt[i] = query(temp);
      |                        ^~~~
      |                        tmp
password.cpp:47:29: error: 'const value_type' {aka 'const struct std::pair<int, std::__cxx11::basic_string<char> >'} has no member named 'se'
   47 |         string a = pq.top().se;
      |                             ^~
password.cpp:49:29: error: 'const value_type' {aka 'const struct std::pair<int, std::__cxx11::basic_string<char> >'} has no member named 'se'
   49 |         string b = pq.top().se;
      |                             ^~
password.cpp:54:17: error: 'mpr' was not declared in this scope
   54 |         pq.push(mpr(b.length(), b));
      |                 ^~~
password.cpp:57:18: error: could not convert 'pq.std::priority_queue<std::pair<int, std::__cxx11::basic_string<char> >, std::vector<std::pair<int, std::__cxx11::basic_string<char> > >, std::greater<std::pair<int, std::__cxx11::basic_string<char> > > >::top()' from 'const value_type' {aka 'const std::pair<int, std::__cxx11::basic_string<char> >'} to 'std::string' {aka 'std::__cxx11::basic_string<char>'}
   57 |     return pq.top();
      |            ~~~~~~^~
      |                  |
      |                  const value_type {aka const std::pair<int, std::__cxx11::basic_string<char> >}
password.cpp:35:9: warning: unused variable 'prev' [-Wunused-variable]
   35 |     int prev = 0;
      |         ^~~~