Submission #1017460


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

std::string S;
int K;
const std::string INF(100, '9');

std::string bigger(const std::string& a, const std::string& b){
    if(a.size() > b.size()){return a;}
    else if(a.size() < b.size()){return b;}
    return a > b ? a : b;
}

std::string smaller(const std::string& a, const std::string& b){
    if(a.size() < b.size()){return a;}
    else if(a.size() > b.size()){return b;}
    return a < b ? a : b;
}

std::string solve200(){
    int S_size = S.size();
    int unitSize = S_size / K;
    
    std::function<std::string(int,int,std::string)> loop = [&](int position, int n, std::string mx){
        if(position == S_size || n == K){
            if(position == S_size && n == K){
                return mx;
            }

            return INF;
        }

        std::string s1 = loop(position + unitSize, n + 1, bigger(mx, S.substr(position, unitSize))),
        s2 = position + unitSize + 1 > S_size ? INF : loop(position + unitSize + 1, n + 1, bigger(mx, S.substr(position, unitSize + 1)));

        return smaller(s1, s2);
    };

    return loop(0, 0, "");
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> K;
    std::cin >> S;
    
    ++K;

    if(S_size <= 16){
        std::cout << solve200() << std::endl;
        return 0;
    }

    std::cout << "-1" << std::endl;
}

Submission Info

Submission Time
Task B - Problem where Commas Separate Digits
User iwashisnake
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1679 Byte
Status CE

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:61:8: error: ‘S_size’ was not declared in this scope
     if(S_size <= 16){
        ^