Submission #518585

#TimeUsernameProblemLanguageResultExecution timeMemory
518585raidTreasure (info1cup19_treasure)C++17
100 / 100
7 ms864 KiB
#include <iostream> #include <vector> #include <string> using namespace std; vector<pair<int, int>> stk; int main() { int n, k; string s; cin >> n >> k >> s; stk.push_back( {s[0], 1} ); for ( int i = 1; i < s.length(); ++i ) { if ( s[i] == stk.back().first ) { ++stk[stk.size() - 1].second; if ( stk[stk.size() - 1].second == k ) { stk.pop_back(); } } else { stk.push_back( {s[i], 1} ); } } for ( int i = 0; i < stk.size(); ++i ) { for ( int j = 0; j < stk[i].second; ++j ) { cout << (char)stk[i].first; } } return 0; }

Compilation message (stderr)

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