Submission #680194

#TimeUsernameProblemLanguageResultExecution timeMemory
680194BeveritaTreasure (info1cup19_treasure)C++17
0 / 100
2 ms468 KiB
#include <bits/stdc++.h> using namespace std; //ifstream in("trampoline.in"); //ofstream out("trampoline.out"); string s; vector<pair<int,string> >v; int n,k,cnt=1; string ind; void mergeVector(){ int contor=0,indice=v.size(); string val=0; for(int i=v.size()-1;i>=0;i--){ if(v[i].first!=0){ if(v[i].second==val){ v[indice].first=0; v[i].first+=contor; contor=v[i].first; indice=i; }else{ contor=v[i].first; indice=i; val=v[i].second; } } } } bool check(){ mergeVector(); for(int i=0;i<v.size();i++){ if(v[i].first>=k)return true; } return false; } int main() { cin>>n>>k; cin>>s; ind=s[0]; for(int i=1;i<s.size();i++){ if(s[i]!=s[i-1]){ v.push_back({cnt,ind}); ind=s[i]; cnt=1; }else{cnt++;} } while(check()){ for(int i=0;i<v.size();i++){ if(v[i].first>=k){ v[i].first-=((v[i].first/k)*k); } } } for(int i=0;i<v.size();i++){ for(int j=1;j<=v[i].first;j++){ cout<<v[i].second; } } return 0; }

Compilation message (stderr)

treasure.cpp: In function 'bool check()':
treasure.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::__cxx11::basic_string<char> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
treasure.cpp: In function 'int main()':
treasure.cpp:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int i=1;i<s.size();i++){
      |                 ~^~~~~~~~~
treasure.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::__cxx11::basic_string<char> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for(int i=0;i<v.size();i++){
      |                     ~^~~~~~~~~
treasure.cpp:66:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::__cxx11::basic_string<char> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...