답안 #873036

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

int cnt[200];

int query(string q);

string guess(int n, int s) {
	for(char c='a'; c<'a'+s; c++){
		string s;
		for(int i=0; i<n; i++) 
			s += c; 	
		cnt[c] = query(s);
	} string ans;
	for(int i=0; i<n; i++){
		string t = ans;
		t += '#';
		for(char c='a'; c<'a'+s; c++){
			if(!cnt[c]) continue;
			if(cnt[c]+ans.size()==n){
				ans += c;
				cnt[c]--;
				break;
			}
			for(int j=1; j<=cnt[c]; j++){
				t += c;
			} bool ok = 0;
			for(char d='a'; d<'a'+s; d++){
				t[ans.size()] = d;
				if(query(t) == t.size()){
					ok = 1;
				}
			} if(!ok){
				ans += c;
				cnt[c]--;
				break;
			} 
			for(int j=1; j<=cnt[c]; j++){
				t.pop_back();
			}
		}
	} return ans;
}

Compilation message

password.cpp: In function 'std::string guess(int, int)':
password.cpp:13:7: warning: array subscript has type 'char' [-Wchar-subscripts]
   13 |   cnt[c] = query(s);
      |       ^
password.cpp:19:12: warning: array subscript has type 'char' [-Wchar-subscripts]
   19 |    if(!cnt[c]) continue;
      |            ^
password.cpp:20:11: warning: array subscript has type 'char' [-Wchar-subscripts]
   20 |    if(cnt[c]+ans.size()==n){
      |           ^
password.cpp:20:24: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |    if(cnt[c]+ans.size()==n){
      |       ~~~~~~~~~~~~~~~~~^~~
password.cpp:22:9: warning: array subscript has type 'char' [-Wchar-subscripts]
   22 |     cnt[c]--;
      |         ^
password.cpp:25:24: warning: array subscript has type 'char' [-Wchar-subscripts]
   25 |    for(int j=1; j<=cnt[c]; j++){
      |                        ^
password.cpp:30:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     if(query(t) == t.size()){
      |        ~~~~~~~~~^~~~~~~~~~~
password.cpp:35:9: warning: array subscript has type 'char' [-Wchar-subscripts]
   35 |     cnt[c]--;
      |         ^
password.cpp:38:24: warning: array subscript has type 'char' [-Wchar-subscripts]
   38 |    for(int j=1; j<=cnt[c]; j++){
      |                        ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 436 KB Execution killed with signal 13
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 231 ms 688 KB Could not guess the password with 50000 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 436 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 436 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -