Submission #1093746

#TimeUsernameProblemLanguageResultExecution timeMemory
1093746DobromirAngelovPassword (RMI18_password)C++14
50 / 100
73 ms872 KiB
#include<bits/stdc++.h> using namespace std; int query(string str); vector<string> seq; priority_queue<pair<int,int> > pq; int queryLetter(char c,int cnt) { string str=""; for(int i=0;i<cnt;i++) str+=c; return query(str); } int mergeQuery(int ind1,int len,string last) { string str=seq[ind1].substr(0,len); reverse(last.begin(), last.end()); str+=last; return query(str); } void mergeSeq(int ind1,int ind2) { string ret=""; int ptr=(int)seq[ind2].size()-1; for(int i=(int)seq[ind1].size()-1;i>=0;i--) { if(ptr>=0) ret+=seq[ind2][ptr]; while(1) { int cnt=mergeQuery(ind1,i+1,ret); if(cnt!=(i+1+(int)ret.size())) { ret.pop_back(); break; } else ptr--; if(ptr<0) break; ret+=seq[ind2][ptr]; } ret+=seq[ind1][i]; } for(int i=ptr;i>=0;i--) ret+=seq[ind2][i]; reverse(ret.begin(), ret.end()); seq[ind1]=ret; } string guess(int n,int s) { for(int i=0;i<s;i++) { int cnt=queryLetter((char)(i+'a'), n); if(cnt>0) { string cur=""; for(int j=0;j<cnt;j++) cur+=(char)(i+'a'); seq.push_back(cur); } } for(int i=0;i<seq.size();i++) { pq.push({-((int)seq[i].size()), i}); } while((int)pq.size()>1) { int ind1=pq.top().second; pq.pop(); int ind2=pq.top().second; pq.pop(); pq.push({-((int)seq[ind1].size()+(int)seq[ind2].size()),ind1}); mergeSeq(ind1,ind2); } int ind=pq.top().second; return seq[ind]; }

Compilation message (stderr)

password.cpp: In function 'std::string guess(int, int)':
password.cpp:64:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for(int i=0;i<seq.size();i++)
      |                 ~^~~~~~~~~~~
#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...