Cod sursa(job #2983165)

Utilizator CalinHanguCalinHangu CalinHangu Data 21 februarie 2023 18:59:41
Problema Sortare topologica Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.89 kb
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>

#define ll long long
#define pb push_back
#define bg begin()
#define ed end()
#define cl clear()
#define pi pair<int, int>

///#define int ll

using namespace std;

ifstream in("cifreco.in");
ofstream out("cifreco.out");

const int MOD = 1e9;
const char nl = '\n';
const int NMAX = 19;

ll dp[NMAX][NMAX + 8], n, x, y;

ll calc( ll x ) {
  ll rez = 1, c, cnt = 0, k = x % 10;
  while( (x /= 10) > 0 ) {
    cnt++;
    k += c = x % 10;
    for(c--; c > 0; c--)
      rez = rez + dp[cnt][k - c];
  }
  return rez;
}

int main() {
    in >> n >> x >> y;
    dp[0][0] = 1;
    for(int i = 1; i <= 18; i++ )
        for(int j = i; j < i + 9; j++ )
            dp[i][j] = dp[i][j - 1] + dp[i - 1][j - 1];
    out << calc(y) - calc(x) + 1 << nl;
  return 0;
}