CSES - Datatähti 2023 alku - Results
Submission details
Task:Kertoma
Sender:snowflake
Submission time:2022-11-04 23:10:44 +0200
Language:C++11
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:46:9: error: 'second' was not declared in this scope
   46 |         second = 0.0;
      |         ^~~~~~
input/code.cpp:54:21: error: expected ';' before 'fac'
   54 |             continue
      |                     ^
      |                     ;
   55 | 
   56 |         fac(e);
      |         ~~~

Code

#include <math.h>
#include<iostream>
using namespace std;

int master[16777216];

void fac(int num)
{
    std::fill_n(master, 0, 0);
    master[0] = 1;
    int inn = 1;
    for (int i = 2; i <= num; i++)
    {
        int nextround = 0;
        for (int i2 = 0; i2 < inn; i2++)
        {
            int product = master[i2] * i + nextround;
            master[i2] = product % 10;
            nextround = product * 0.1;
        }

        while (nextround > 0)
        {
            master[inn] = nextround % 10;
            nextround = nextround * 0.1;
            inn++;
        }
    }
}

int main()
{
    int nil, one, two, three, four, five, six, seven, eight, nine;
    cin >> nil >> one >> two >> three >> four >> five >> six >> seven >> eight >> nine;
    int numz[] = { nil, one, two, three, four, five, six, seven, eight, nine };

    int numsum = 0;
    for (int i = 0; i <= 10; ++i)
        numsum += numz[i];


    int wa = 0;
    int kick = (int)(0.84 * pow(numsum, 0.89543) + 1);
    for (int e = kick; e <= 16777216; ++e)
    {
        second = 0.0;
        for (int i = 1; i <= e; ++i)
        {
            second += log10(i);
        }
        second = (int)(second + 1);

        if (second != numsum)
            continue

        fac(e);

        int counters[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        for (int z = 0; z < 16777216; ++z)
        {
            counters[master[z]]++;
        }
        int z0 = counters[0];
        counters[0] = 16777216 - z0 - 1;

        bool spill = false;
        for (int k = 0; k < 10; ++k)
        {
            spill = counters[k] != numz[k];
            if (spill)
                break;
        }
        if (!spill)
        {
            wa = e;
            break;
        }
    }

    cout << wa;


    return 0;
}