Submission #773299

# Submission time Handle Problem Language Result Execution time Memory
773299 2023-07-04T20:09:45 Z BT21tata Password (RMI18_password) C++17
30 / 100
82 ms 436 KB
#include <bits/stdc++.h>
using namespace std;

struct cmp
{
 	bool operator()(const string &a, const string &b)
  	{
    	return a.size()>b.size();
  	}
};

int query(string str);

string mrg(string &a, string &b)
{
  	string ret;
  	int pos1=0, pos2=0;
  	while(true)
  	{
    	if(pos1==a.size() or pos2==b.size()) break;
    	string cur=ret;
    	cur+=a[pos1];
    	for(int i=pos2; i<b.size(); i++)
      		cur+=b[i];
    	int q=query(cur);
    	if(q==pos1+b.size()+1)
      		ret+=a[pos1++];
    	else ret+=b[pos2++];
  	}
  	while(pos1<a.size()) ret+=a[pos1++];
  	while(pos2<b.size()) ret+=b[pos2++];
  	return ret;
}


string guess(int n, int s)
{
  	priority_queue<string, vector<string>, cmp>q;
  	for(int i=0; i<s; i++)
  	{
    	string ss, sec;
    	for(int j=0; j<n; j++)
      		ss+=(char)(i+'a');
    	int ret=query(ss);

    	if(!ret) continue;
    	for(int j=0; j<ret; j++)
     		sec+=(char)(i+'a');

    	q.push(sec);
  	}

  	while(q.size()>1)
  	{
    	string s1=q.top(); q.pop();
    	string s2=q.top(); q.pop();
    	string merged=mrg(s1, s2);
    	q.push(merged);
  	}
  	return q.top();
}

Compilation message

password.cpp: In function 'std::string mrg(std::string&, std::string&)':
password.cpp:20:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |      if(pos1==a.size() or pos2==b.size()) break;
      |         ~~~~^~~~~~~~~~
password.cpp:20:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |      if(pos1==a.size() or pos2==b.size()) break;
      |                           ~~~~^~~~~~~~~~
password.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |      for(int i=pos2; i<b.size(); i++)
      |                      ~^~~~~~~~~
password.cpp:26:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |      if(q==pos1+b.size()+1)
      |         ~^~~~~~~~~~~~~~~~~
password.cpp:30:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |    while(pos1<a.size()) ret+=a[pos1++];
      |          ~~~~^~~~~~~~~
password.cpp:31:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |    while(pos2<b.size()) ret+=b[pos2++];
      |          ~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 57 queries.
2 Correct 1 ms 208 KB Guessed the password with 105 queries.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 49 queries.
2 Correct 1 ms 208 KB Guessed the password with 90 queries.
3 Correct 2 ms 208 KB Guessed the password with 92 queries.
4 Runtime error 1 ms 304 KB Execution killed with signal 13
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 312 KB Guessed the password with 2750 queries.
2 Correct 47 ms 308 KB Guessed the password with 5071 queries.
3 Correct 33 ms 436 KB Guessed the password with 4587 queries.
4 Correct 82 ms 332 KB Guessed the password with 8084 queries.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 57 queries.
2 Correct 1 ms 208 KB Guessed the password with 105 queries.
3 Correct 1 ms 208 KB Guessed the password with 49 queries.
4 Correct 1 ms 208 KB Guessed the password with 90 queries.
5 Correct 2 ms 208 KB Guessed the password with 92 queries.
6 Runtime error 1 ms 304 KB Execution killed with signal 13
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 57 queries.
2 Correct 1 ms 208 KB Guessed the password with 105 queries.
3 Correct 1 ms 208 KB Guessed the password with 49 queries.
4 Correct 1 ms 208 KB Guessed the password with 90 queries.
5 Correct 2 ms 208 KB Guessed the password with 92 queries.
6 Runtime error 1 ms 304 KB Execution killed with signal 13
7 Halted 0 ms 0 KB -