Submission #476097

#TimeUsernameProblemLanguageResultExecution timeMemory
476097stefantagaPassword (RMI18_password)C++14
100 / 100
251 ms608 KiB
#include <bits/stdc++.h> #include <fstream> #include <iostream> #include <sstream> #include <string> #include <stdlib.h> #include <assert.h> using namespace std; int query(string str); string sol,acum; int n,s; char litera[105]; bool intreaba(char litera,int x) { string acum; for (int i=1;i<=x;i++) { acum.push_back(litera); } if (query(acum)==x) { return 1; } return 0; } int fr[105],poz,pozitie,inainte[1005],ceau[5005]; char finalsol[5005]; bool compare (int a,int b) { return fr[a]>fr[b]; } string divide(int st,int dr) { if (st==dr) { string acum; for (int i=1;i<=fr[st];i++) { acum.push_back(litera[st]); } return acum; } int mij=(st+dr)/2; string stanga=divide(st,mij); string dreapta=divide(mij+1,dr); string panaacum; while (stanga.size()&&dreapta.size()) { string ceintreb = panaacum+stanga[0]+dreapta; if (query(ceintreb)==ceintreb.size()) { panaacum+=stanga[0]; stanga.erase(stanga.begin()); } else { panaacum+=dreapta[0]; dreapta.erase(dreapta.begin()); } } panaacum+=stanga; panaacum+=dreapta; return panaacum; } string guess (int N,int S) { int i,st,dr,mij,sol,j,k; n=N;s=S; for (i=1;i<=s;i++) { litera[i]=(char(i+96)); st=1; dr=n; sol=0; while (st<=dr) { mij=(st+dr)/2; if (intreaba(litera[i],mij)==1) { sol=mij; st=mij+1; } else { dr=mij-1; } } fr[i]=sol; } string salut=divide(1,s); return salut; }

Compilation message (stderr)

password.cpp: In function 'std::string divide(int, int)':
password.cpp:52:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         if (query(ceintreb)==ceintreb.size())
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
password.cpp: In function 'std::string guess(int, int)':
password.cpp:69:25: warning: unused variable 'j' [-Wunused-variable]
   69 |     int i,st,dr,mij,sol,j,k;
      |                         ^
password.cpp:69:27: warning: unused variable 'k' [-Wunused-variable]
   69 |     int i,st,dr,mij,sol,j,k;
      |                           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...