답안 #680196

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680196 2023-01-10T07:47:44 Z Beverita Treasure (info1cup19_treasure) C++17
100 / 100
7 ms 1444 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;
    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++;}
    }

    v.push_back({cnt,ind});

    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:61: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]
   61 |         for(int i=0;i<v.size();i++){
      |                     ~^~~~~~~~~
treasure.cpp:70: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]
   70 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 296 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 2 ms 572 KB Output is correct
18 Correct 2 ms 568 KB Output is correct
19 Correct 2 ms 716 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 3 ms 980 KB Output is correct
22 Correct 3 ms 980 KB Output is correct
23 Correct 4 ms 824 KB Output is correct
24 Correct 5 ms 1068 KB Output is correct
25 Correct 5 ms 1064 KB Output is correct
26 Correct 6 ms 868 KB Output is correct
27 Correct 7 ms 868 KB Output is correct
28 Correct 6 ms 1096 KB Output is correct
29 Correct 6 ms 1096 KB Output is correct
30 Correct 7 ms 1416 KB Output is correct
31 Correct 7 ms 1444 KB Output is correct
32 Correct 6 ms 1416 KB Output is correct
33 Correct 6 ms 1444 KB Output is correct
34 Correct 6 ms 1412 KB Output is correct
35 Correct 7 ms 1444 KB Output is correct