# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
709414 | salmon | Password (RMI18_password) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
//int query(string str);
string guess(int N, int S){
int t = 0;
struct node{
int v;
node *l,*r;
node(int s){
v = s;
l = NULL;
r = NULL;
}
}*aas,*infront,*inback;
aas = new node(0);
string alphabet = "";
for(int i = 'a'; i < 'a' + S; i++){
alphabet.push_back(i);
}
inback = aas -> r;
infront = aas;
for(int i = 1; i <= N - 30; i++){
string temp = "";
string temp1 = "";
node *point = aas;
while(point != inback){
if(point -> v == 0){
point = point -> r;
}
else{
temp.push_back(point -> v);
point = point -> r;
}
}
point = inback;
while(point != NULL){
if(point -> v == 0){
point = point -> r;
}
else{
temp1.push_back(point -> v);
point = point -> r;
}
}
if(query(temp + alphabet + temp1) < i){
inback = infront;
infront = infront -> l;
i--;
continue;
}
int s = 'a';
int e = 'a' + S - 1;
while(s != e){
int m = (s + e)/2;
string temp2 = temp;
for(int i = s; i <= m; i++){
temp2.push_back(s);
}
temp2 = temp2 + temp1;
if(query(temp2) >= i){
e = m;
}
else{
s = m + 1;
}
}
node *temp3 = new node(s);
infront -> r = temp3;
temp3 -> l = infront;
infront = temp3;
inback = temp3 -> r;
}
for(int i = max(1,N - 29); i <= N; i++){
string temp = "";
string temp1 = "";
node *point;
point = aas;
while(point != inback){
if(point -> v == 0){
point = point -> r;
}
else{
temp.push_back(point -> v);
point = point -> r;
}
}
point = inback;
while(point != NULL){
if(point -> v == 0){
point = point -> r;
}
else{
temp1.push_back(point -> v);
point = point -> r;
}
}
// cout << "s" + temp + " " + temp1 << endl;
int s = 'a';
int e = 'a' + S - 1;
string temp2;
for(char j = s; j <= e; j++){
temp2 = temp;
temp2.push_back(j);
temp2 = temp2 + temp1;
//cout << temp2 << endl;
if(query(temp2) == i){
//cout << "j = " << j << endl;
node *temp3 = new node(j);
infront -> r = temp3;
temp3 -> l = infront;
infront = temp3;
temp3 -> r = inback;
temp = temp2;
break;
}
}
if(query(temp) < i){
inback = infront;
infront = infront -> l;
i--;
continue;
}
}
string temp = "";
string temp1 = "";
node *point = aas;
while(point != NULL){
if(point -> v == 0){
point = point -> r;
}
else{
temp1.push_back(point -> v);
point = point -> r;
}
}
return temp + temp1;
}
/*
26 26 nabcdefghjiklmopqrstuvwxyz
*/