From 3a00649b9318e0a177401f7b52be9cf846e5a527 Mon Sep 17 00:00:00 2001 From: Pedro Ulisses Date: Mon, 17 Oct 2022 09:32:58 -0300 Subject: [PATCH] lol --- kekw.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 kekw.cpp diff --git a/kekw.cpp b/kekw.cpp new file mode 100644 index 0000000..5509516 --- /dev/null +++ b/kekw.cpp @@ -0,0 +1,45 @@ +#include "bits/stdc++.h" +using namespace std; + +int dp[20][200][2]; + +int digitDP(int idx, int sum, int can, vector &digit) +{// idx eh o indice atual, sum a soma dos digitos ate idx, +//e can uma flag para indicar se pode colocar +//qualquer valor a partir daqui + if(idx == (int)digit.size()) + return sum; + if(dp[idx][sum][can] != -1) + return dp[idx][sum][can]; + int ans = 0; + for(int i = 0; i < 10; i++) + if(can or i <= digit[idx]) + ans += digitDP(idx + 1, sum + i, + can or i < digit[idx], digit); + return dp[idx][sum][can] = ans; +} + +int query(int x) // responde a consulta de 0 ate x +{ + memset(dp, -1, sizeof(dp)); + vector digit; + while(x) + { + digit.push_back(x%10); + x /= 10; + } + reverse(digit.begin(), digit.end()); + return digitDP(0, 0, 0, digit); +} + +int main() +{ + int q, a, b; + cin >> q; + while(q--) + { + cin >> a >> b; + cout << query(b) - query(a - 1) << '\n'; + } + return 0; +}