Cod sursa(job #3216920)

Utilizator Robert_MitriRobert Mitri Robert_Mitri Data 20 martie 2024 13:14:45
Problema Diviz Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.19 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
ifstream fin("diviz.in");
ofstream fout("diviz.out");

int n,k,a,b;

int d[2][205][205][105];
int pr[205][10];

int ind = 0;

const int mod = 30103;

string s;

int main()
{
    fin>>k>>a>>b;
    fin>>s;
    s="0"+s;
    for(int i = s.size()-1;i>=0;i--){
        for(int c=0;c<=9;c++)
            pr[i][c]+=pr[i+1][c];
        if(i!=s.size()-1)
            pr[i][s[i+1]-'0']=i+1;
    }
    for(int i=1;i<s.size();i++)
        d[ind][1][s[i]-'0'][(s[i]-'0')%k]++;
    int sol=0;
    for(int lg = 2;lg<=b;lg++,ind=1-ind)
    {
        memset(d[1-ind],0,sizeof(d[1-ind]));
        for(int i = lg;i<s.size();i++)
            for(int r=0;r<k;r++)
                for(int c=0;c<=9;c++)
                if(d[ind][i][r][c] && pr[i][c]){
                        d[1-ind][pr[i][c]][(r*10+s[i]-'0')%k][c]+=d[ind][i][r][c];
                        d[1-ind][pr[i][c]][(r*10+s[i]-'0')%k][c]%=mod;
        }
        if(lg>=a)
            for(int i=lg;i<s.size();i++)
                for(int c=0;c<=9;c++)
                    sol=(sol+d[1-ind][i][0][c])%mod;
    }
    fout<<sol;

}