Cod sursa(job #3336752)

Utilizator bogdan1479Luca Bogdan Alexandru bogdan1479 Data 25 ianuarie 2026 17:43:06
Problema Diviz Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.29 kb
#include <fstream>
#include <cstring>

using namespace std;

const int NMAX = 202, KMAX = 101, MOD = 30103;

ifstream fin("diviz.in");
ofstream fout("diviz.out");

int k, a, b, x, modcrt, sol,
    dp[NMAX][KMAX], temp[NMAX][KMAX],
    ult[10][NMAX][KMAX],
    val, scad, adaug;

char n[NMAX];

int main()
{
    fin >> k >> a >> b >> n;
    int lg = strlen(n);
    for(int i = 1; i <= lg; ++i)
    {
        x = n[i - 1] - '0';
        if(x) temp[1][x % k] = (temp[1][x % k] + 1) % MOD;
        for(int nrc = 1; nrc < i; ++nrc)
            for(int mod = 0; mod < k; ++mod)
                if(dp[nrc][mod])
                {
                    modcrt = (mod * 10 + x) % k;
                    temp[nrc + 1][modcrt] = (temp[nrc + 1][modcrt] + dp[nrc][mod]) % MOD;
                }
        for(int nrc = 1; nrc <= i; ++nrc)
            for(int mod = 0; mod < k; ++mod)
            {
                val = temp[nrc][mod];
                scad = ult[x][nrc][mod];
                adaug = (val - scad + MOD) % MOD;
                dp[nrc][mod] = (dp[nrc][mod] + adaug) % MOD;
                ult[x][nrc][mod] = val;
                temp[nrc][mod] = 0;
            }
    }
    for(int nrc = a; nrc <= b; ++nrc) sol = (sol + dp[nrc][0]) % MOD;
    fout << sol;
    return 0;
}