// Sample grader for contestants' use.
//
// Usage: place your input data in the file password.in in the format
//
// line 1: N S
// line 2: hidden_password
//
// Then compile this grader together with your implementation.
// Run the binary to see your guessing strategy at work!
// Set DEBUG to 1 to print all queries.
#include <bits/stdc++.h>
using namespace std;
int query(string q);
#define fi first
#define se second
#define pb push_back
#define mp make_pair
string join(string a,string b){
int la=a.length(),lb=b.length();
string q=b+a;
string ans;
int done=0;
for(int i=0;i<=la;i++){
int ret=query(q);
int newb=ret-la-done;
int sz=(int)ans.size();
for(int j=done;j<done+newb;j++){
ans.pb(b[j]);
}
ans.pb(a[i]);
q=ans;
for(int j=done+newb;j<lb;j++)q.pb(b[j]);
for(int j=i+1;j<la;j++)q.pb(a[j]);
done+=newb;
}
return ans;
}
string guess(int n, int s){
priority_queue<pair<int,string>,vector<pair<int,string> >,greater<pair<int,string> > > pq;
int occ[26];
for(int i=0;i<s;i++){
string q="";
for(int j=0;j<n;j++)q.pb(i+'a');
occ[i]=query(q);
q="";
for(int j=0;j<occ[i];j++)q.pb(i+'a');
if(occ[i]>0)pq.push(mp(occ[i],q));
}
while((int)pq.size()>1){
pair<int,string> cur1=pq.top();pq.pop();
pair<int,string> cur2=pq.top();pq.pop();
pq.push(mp(cur1.fi+cur2.fi,join(cur1.se,cur2.se)));
}
return pq.top().se;
}
Compilation message
password.cpp: In function 'std::__cxx11::string join(std::__cxx11::string, std::__cxx11::string)':
password.cpp:27:7: warning: unused variable 'sz' [-Wunused-variable]
int sz=(int)ans.size();
^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Token "ab |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
Token "bbbbbbaabbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaa" doesn't correspond to pattern "[a-b]{1,50}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
256 KB |
Token "dddab |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Token "ab |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Token "ab |
2 |
Halted |
0 ms |
0 KB |
- |