답안 #680194

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680194 2023-01-10T07:43:22 Z Beverita Treasure (info1cup19_treasure) C++17
0 / 100
2 ms 468 KB
#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

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++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -