Cod sursa(job #3336751)

Utilizator bogdan1479Luca Bogdan Alexandru bogdan1479 Data 25 ianuarie 2026 17:40:43
Problema Diviz Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.35 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] = (1 + temp[1][x % k]) % 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)
                if(temp[nrc][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;
}