#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define mp make_pair
//#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
using namespace std;
const int mod=1e9+7;
const int modp=1999999973;
const int modulo=998244353;
int cnt[26];
int query(string str);
string guess(int n,int s){
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
srand(chrono::steady_clock::now().time_since_epoch().count());
vector<char>tz;
for(int i=0;i<s;i++){
tz.push_back(i+'a');
string empt="";
for(int j=1;j<=n;j++) empt.push_back(i+'a');
cnt[i]=query(empt);
}
string ans;
while(ans.size()!=n){
for(int i=0;i<=ans.size();i++){
random_shuffle(all(tz));
for(int j=0;j<tz.size();j++){
if(cnt[tz[j]-'a']){
string ask = ans.substr(0,i) + tz[j] + ans.substr(i,ans.size()-i);
if(query(ask)==ans.size()+1){
ans=ans.substr(0,i) + tz[j] +ans.substr(i,ans.size()-i);
cnt[tz[j]-'a']--;
goto next;
}
}
}
}
next:;
}
return ans;
}
Compilation message
password.cpp: In function 'std::__cxx11::string guess(int, int)':
password.cpp:38:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(ans.size()!=n){
~~~~~~~~~~^~~
password.cpp:39:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<=ans.size();i++){
~^~~~~~~~~~~~
password.cpp:41:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<tz.size();j++){
~^~~~~~~~~~
password.cpp:44:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(query(ask)==ans.size()+1){
~~~~~~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
384 KB |
Guessed the password with 459 queries. |
2 |
Correct |
19 ms |
360 KB |
Guessed the password with 1410 queries. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
384 KB |
Guessed the password with 1198 queries. |
2 |
Correct |
47 ms |
384 KB |
Guessed the password with 5178 queries. |
3 |
Correct |
20 ms |
384 KB |
Guessed the password with 1927 queries. |
4 |
Correct |
111 ms |
384 KB |
Guessed the password with 14293 queries. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
421 ms |
384 KB |
Could not guess the password with 50000 queries. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
384 KB |
Guessed the password with 459 queries. |
2 |
Correct |
19 ms |
360 KB |
Guessed the password with 1410 queries. |
3 |
Correct |
18 ms |
384 KB |
Guessed the password with 1198 queries. |
4 |
Correct |
47 ms |
384 KB |
Guessed the password with 5178 queries. |
5 |
Correct |
20 ms |
384 KB |
Guessed the password with 1927 queries. |
6 |
Correct |
111 ms |
384 KB |
Guessed the password with 14293 queries. |
7 |
Incorrect |
421 ms |
384 KB |
Could not guess the password with 50000 queries. |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
384 KB |
Guessed the password with 459 queries. |
2 |
Correct |
19 ms |
360 KB |
Guessed the password with 1410 queries. |
3 |
Correct |
18 ms |
384 KB |
Guessed the password with 1198 queries. |
4 |
Correct |
47 ms |
384 KB |
Guessed the password with 5178 queries. |
5 |
Correct |
20 ms |
384 KB |
Guessed the password with 1927 queries. |
6 |
Correct |
111 ms |
384 KB |
Guessed the password with 14293 queries. |
7 |
Incorrect |
421 ms |
384 KB |
Could not guess the password with 50000 queries. |
8 |
Halted |
0 ms |
0 KB |
- |