// 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
map<string,int> ma;
int qry(string q){
if(ma.find(q)!=ma.end())return ma[q];
return ma[q]=query(q);
}
string join(string a,string b){
int la=a.length(),lb=b.length();
string ans=a;
int idx=0;
for(int i=0;i<lb;i++){
while(true){
string q="";
for(int j=0;j<idx;j++){
q.pb(ans[j]);
}
q.pb(b[i]);
for(int j=idx;j<(int)ans.size();j++){
q.pb(ans[j]);
}
if(qry(q)==(int)q.size()){
ans=q;
break;
}else{
idx++;
}
}
}
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];
int sum=0;
for(int i=0;i<s-1;i++){
string q="";
for(int j=0;j<n;j++)q.pb(i+'a');
occ[i]=qry(q);
q="";
for(int j=0;j<occ[i];j++)q.pb(i+'a');
if(occ[i]>0)pq.push(mp(occ[i],q));
sum+=occ[i];
}
occ[s-1]=n-sum;
string q="";for(int j=0;j<occ[s-1];j++)q.pb(s-1+'a');if(occ[s-1]>0)pq.push(mp(occ[s-1],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:26:6: warning: unused variable 'la' [-Wunused-variable]
int la=a.length(),lb=b.length();
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Guessed the password with 78 queries. |
2 |
Correct |
2 ms |
384 KB |
Guessed the password with 156 queries. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Guessed the password with 47 queries. |
2 |
Correct |
4 ms |
384 KB |
Guessed the password with 92 queries. |
3 |
Correct |
2 ms |
384 KB |
Guessed the password with 90 queries. |
4 |
Execution timed out |
3084 ms |
361692 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3110 ms |
387192 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Guessed the password with 78 queries. |
2 |
Correct |
2 ms |
384 KB |
Guessed the password with 156 queries. |
3 |
Correct |
1 ms |
256 KB |
Guessed the password with 47 queries. |
4 |
Correct |
4 ms |
384 KB |
Guessed the password with 92 queries. |
5 |
Correct |
2 ms |
384 KB |
Guessed the password with 90 queries. |
6 |
Execution timed out |
3084 ms |
361692 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Guessed the password with 78 queries. |
2 |
Correct |
2 ms |
384 KB |
Guessed the password with 156 queries. |
3 |
Correct |
1 ms |
256 KB |
Guessed the password with 47 queries. |
4 |
Correct |
4 ms |
384 KB |
Guessed the password with 92 queries. |
5 |
Correct |
2 ms |
384 KB |
Guessed the password with 90 queries. |
6 |
Execution timed out |
3084 ms |
361692 KB |
Time limit exceeded |