답안 #855647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855647 2023-10-01T15:41:44 Z franfill Password (RMI18_password) C++17
0 / 100
2 ms 436 KB
#include<bits/stdc++.h>
using namespace std;

int query(string S);

int query(string S, bool rv)
{
	if (rv)
		reverse(S.begin(), S.end());
	return query(S);
}

string cur = "";
int N, S;

void solve(int i, vector < bool > us, bool rv)
{
	if (cur.size() == N)
		return;
	for (int c = 0; c < S; c++)
		if (us[c])
		{
			string tr = cur.substr(0, i);	
			tr += char('a'+c);
			tr += cur.substr(i, cur.size()-i);
			if (query(tr, rv) == tr.size())
			{
				cur = tr;
				solve(i, us, rv);
				solve(i+1, us, rv);
				return;
			}
			else
				us[c] = false;
		}
}

string guess(int N, int S)
{	
	::N = N;
	::S = S;
	cur = "";
	vector < bool > us(S, true);
	for (int c = 0; c < S; c++)
		if (query(string(1, c+'a')) == true)
		{
			cur = string(1, c+'a');
			break;
		}
		else
			us[c] = false;
	solve(1, us, false);
	reverse(cur.begin(), cur.end());
	solve(cur.size(), us, true);
	reverse(cur.begin(), cur.end());
	return cur;
}

Compilation message

password.cpp: In function 'void solve(int, std::vector<bool>, bool)':
password.cpp:18:17: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   18 |  if (cur.size() == N)
      |      ~~~~~~~~~~~^~~~
password.cpp:26:22: 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 (query(tr, rv) == tr.size())
      |        ~~~~~~~~~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Returned early from guess() after 103 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 436 KB Returned early from guess() after 89 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 344 KB Returned early from guess() after 358 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Returned early from guess() after 103 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Returned early from guess() after 103 queries.
2 Halted 0 ms 0 KB -