Submission #1069972

# Submission time Handle Problem Language Result Execution time Memory
1069972 2024-08-22T10:44:22 Z AdamGS Password (RMI18_password) C++17
0 / 100
9 ms 428 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
int query(string p);
string guess(int n, int s) {
	vector<pair<int,string>>A;
	rep(i, s) {
		string p="";
		rep(j, n) p+=char(i+'a');
		int x=query(p);
		while(p.size()>x) p.pop_back();
		if(x) A.pb({x, p});
	}
	while(A.size()>1) {
		sort(all(A));
		reverse(all(A));
		string a=A[A.size()-1].nd, b=A[A.size()-2].nd;
		A.pop_back(); A.pop_back();
		int l=0;
		string ans="";
		for(auto i : a) {
			string x=ans;
			x+=i;
			for(int j=l; j<b.size(); ++j) x+=b[j];
			while(query(x)<x.size()) {
				ans+=b[l];
				++l;
				x=ans;
				x+=i;
				for(int j=l; j<b.size(); ++j) x+=b[j];
			}
			ans+=i;
		}
		A.pb({ans.size(), ans});
	}
	return A[0].nd;
}

Compilation message

password.cpp: In function 'std::string guess(int, int)':
password.cpp:16:17: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   16 |   while(p.size()>x) p.pop_back();
      |         ~~~~~~~~^~
password.cpp:29:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |    for(int j=l; j<b.size(); ++j) x+=b[j];
      |                 ~^~~~~~~~~
password.cpp:30:18: 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(query(x)<x.size()) {
      |          ~~~~~~~~^~~~~~~~~
password.cpp:35:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int j=l; j<b.size(); ++j) x+=b[j];
      |                  ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Returned early from guess() after 34 queries.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Guessed the password with 52 queries.
2 Correct 1 ms 344 KB Guessed the password with 92 queries.
3 Correct 1 ms 344 KB Guessed the password with 105 queries.
4 Incorrect 1 ms 428 KB Returned early from guess() after 175 queries.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 344 KB Returned early from guess() after 1617 queries.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Returned early from guess() after 34 queries.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Returned early from guess() after 34 queries.
2 Halted 0 ms 0 KB -