답안 #873077

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
873077 2023-11-14T12:13:14 Z vjudge1 Password (RMI18_password) C++17
0 / 100
256 ms 444 KB
#include<bits/stdc++.h>
using namespace std;

int a[26];
int cnt[26];
set<char>st[26];

int query(string q);

string guess(int n, int s) {
	set<pair<int, string>>st;
	for(char c='a'; c<'a'+s; c++){
		string s;
		for(int i=1; i<=n; i++)
			s += c;
		cnt[c-'a'] = query(s);
		while(s.size() > cnt[c-'a']) 
			s.pop_back();
		if(s.size()) st.insert({s.size(), s});
	} 
	while(st.size() > 1){
		string a = st.begin()->second;
		st.erase(st.begin());
		string b = st.begin()->second;
		st.erase(st.begin());
		string c; int l = 0, r = 0;
		while(c.size() < a.size()+b.size()){
			if(r < b.size()){
				c += b[r];
			}
			for(int j=l; j<a.size(); j++) 
				c += a[j];
			if(query(c) == c.size()){
				r++;
				for(int j=l; j<a.size(); j++)
					c.pop_back();
			} else{
				for(int j=l; j<=a.size(); j++)
					c.pop_back();
				c += a[l++];
			}
		} st.insert({c.size(), c});
	}
	return st.begin()->second;
}

Compilation message

password.cpp: In function 'std::string guess(int, int)':
password.cpp:17:18: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   17 |   while(s.size() > cnt[c-'a'])
      |         ~~~~~~~~~^~~~~~~~~~~~
password.cpp:28:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |    if(r < b.size()){
      |       ~~^~~~~~~~~~
password.cpp:31:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |    for(int j=l; j<a.size(); j++)
      |                 ~^~~~~~~~~
password.cpp:33:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |    if(query(c) == c.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<a.size(); j++)
      |                  ~^~~~~~~~~
password.cpp:38:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int j=l; j<=a.size(); j++)
      |                  ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 256 ms 344 KB Could not guess the password with 50000 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 436 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 244 ms 444 KB Could not guess the password with 50000 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 256 ms 344 KB Could not guess the password with 50000 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 256 ms 344 KB Could not guess the password with 50000 queries.
2 Halted 0 ms 0 KB -