Source Code
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <stdlib.h>
#include <time.h>
#include <stack>
#include <map>
#include <math.h>
#include <cmath>
#include <string.h>
#include <numeric>
using namespace std;
typedef vector<int> vi ;
typedef long long ll;
#define all(x) (x).begin() , (x).end()
#define allR(x) (x).rbegin() , (x).rend()
#define pb push_back
const int N = 1e6, M=1e6+1, NN=1e8 , MX = 1e6+1;
const ll MXL=1e18 , MOD = 1e9 + 7 ;
int a[N];
map<char,int> mp;
int main(){
    // freopen("input.txt", "r", stdin);
    int n, k;
    bool flag=0;
    cin >> n >> k;
    string s, ans, add;
    cin >> s;
    vector<pair<int, char>> v;
    for(int i=0 ; i<n ; i++ )
        mp[s[i]]++;
    for(char c='a' ; c<='z' ; c++)
        v.pb({mp[c],c});

    sort(allR(v));
    for(int i=0 ; i<v.size() ; i++ ){
        if( v[i].first >=k )
            ans+=v[i].second;
    }
    for(int i=0 ; i<v.size() ; i++ ){
        if( v[i].first && (v[i].first)%k >= (v[i].first)/k )
            add+=v[i].second;
    }
    // cout << ans <<"  "<<add<<" ";;
    if(!ans.size())
        puts("3");
    else{
        if(!add.size())
            puts("1");
        else
            puts("2");
        for(int i=0 ; i<k ; i++)
            cout<<ans;
        cout<<add;
    }
    return 0 ;
}
Copy
Repeating Strings Rand()
GNU G++17
30 ms
1.8 MB
Wrong Answer
Test Case #1
1 ms
360 KB
Accepted
Input
12 3
aaccbbabcddd
Output
1
dcbadcbadcba
Judge Output
1
abcdabcdabcd
Checker Message
The type and the string are correct
Test Case #2
0 ms
396 KB
Accepted
Input
10 2
zigzagiaai
Output
2
iazgiazgia
Judge Output
2
aigzaigzai
Checker Message
The type and the string are correct
Test Case #3
0 ms
576 KB
Accepted
Input
7 4
fegtyta
Output
3
Judge Output
3
Checker Message
The string is of the type 3
Test Case #4
27 ms
1.6 MB
Accepted
Input
843011 148379
aksbudtkbphdbiverwnrdxntqdwbyhemsmkkjuqmejtfzdvwseeivlfbeeygsxsjkjtzhnnyklrahltppzwvicotmjyjckdaxqabahqxdiksiwopkdwecgymjxdhjqmkvurvujemovqycdhdlfvxhegbbhlzhkscykonkzusoymktoafzsvdmqusqlsoaqifsayosgytkzsztucgrycqasivtshsejpknmdqzsnhizk...
Output
3
Judge Output
3
Checker Message
The string is of the type 3
Test Case #5
30 ms
1.7 MB
Accepted
Input
959139 926507
uywqcfkbfwlniomreqcmunpcdeymhmxqsvkgyrbiolnfgnzlczyobkoncjhixnncaoaakrupfstigreivmpttrhlmodpxmieeikgzpmdmrwbbmyjhschxgdvmvakxeepsoghakcmpnrtdutugbdalnryvwpcymyuicsglymksdkwfysrmyylwkeatxchcxwoohascwtvehtfbxgpbmsxypicozibdwvbhafwtlvjlkp...
Output
3
Judge Output
3
Checker Message
The string is of the type 3
Test Case #6
1 ms
592 KB
Accepted
Input
9859 7515
wpyigtqspdxdgddtsioeudsmnojjkcamohulielbmhjisfuypwsujpmvqbujcfdlmiqmlrntfjvfhhjbnmsqgdknzjaycxpfgfzwpppktpqqcdwcxtxunfqnfyubmqekntjgqdyslewbmvkgqhidgvdbxtqgqenvxehelpbirdsyqyoycpldxngydiurzmigkovwqfcvssasjtpgbwjmieloaqdcfqutbbrpomhdrngukav...
Output
3
Judge Output
3
Checker Message
The string is of the type 3
Test Case #7
4 ms
952 KB
Accepted
Input
125987 49792
anaoteycowwesxfybczrvxktnpcgeqlxgzzinjgritwjvrqjvvfhzxvyjdireflitjcuxxsvcnwuucjlmfxpprumqqhvokjnhaaboesidsdxernnklxszmihxzmkbwrxyzjpwuulinvycoifkgdebbgbefxjuezabszhyqlxppljkeykmwtqrjbqyezfjjmyrmscgorqngkgtpwxqojsyuabcbvsoxatwgbvhnoyvitw...
Output
3
Judge Output
3
Checker Message
The string is of the type 3
Test Case #8
7 ms
1.1 MB
Accepted
Input
209411 76302
ktzqqcfbuopjvdkofcsdgrunmbiishnaduqoisioisozduojprzbpjusrdvlcewzpatgbikbualpuootbnjrzdvakgtavwzbbyrdzcgtlfffrkpubwwprpqvclldsvhvxvzqfjqugbbvzardvyzmltmegprguzetqmorjcnovqgpbfrhkzkupszdgbzajfnjpfklmbbaygluospwufgieqniltynjhanakhkphjrxagj...
Output
3
Judge Output
3
Checker Message
The string is of the type 3
Test Case #9
10 ms
1.2 MB
Accepted
Input
325539 230213
oeuwsgvfnskqwdijjludwtxdhkwgphpgglcrwlypjwxfjuwhuuilhxkuvebnsxfcicrtlrzvnfxeiiprfrlzmtwauclbjqdbrkvbbvtsgtzofthlqedgbfpmejqtxpxfveqlobozuzwlkkapllcwllydkygzozdidcdzpcwqpbpbsimdevwahpinibzlfjkfgkaajdnfcsjlrvfngjxxvlutjuuuyvepgefkyzrnbfm...
Output
3
Judge Output
3
Checker Message
The string is of the type 3
Test Case #10
26 ms
1.8 MB
Wrong Answer
Input
843011 247
fqilwnuqirjdfzdunivjbftpuxtlwzgepmgdogqzvmlkctervukcjjhooxjkojevjjbgqchbnnctkrwpupqnikqzrqtsrplrudpxhcicqtasqhpfbswtelmlqvvoezyuproduwtodpkapejxsmrgzxcfbxvzzvkyhqfmxexwbbxyetklemaobplnbijvcdseknxtvzdabtbezllopavcsgtwossjgapfpvzmhidtyjmihu...
Output
1
hqnbigcsazyrvodetkmufplwxjhqnbigcsazyrvodetkmufplwxjhqnbigcsazyrvodetkmufplwxjhqnbigcsazyrvodetkmufplwxjhqnbigcsazyrvodetkmufplwxjhqnbigcsazyrvodetkmufplwxjhqnbigcsazyrvodetkmufplwxjhqnbigcsazyrvodetkmufplwxjhqnbigcsazyrvodetkmufplwxjhqnbigcsazyrv...
Judge Output
1
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...
Checker Message
The string doesn't contain the same letters from the input