Submission
Status:
PPPPPPTPTT
Subtask/Task Score:
70/100
Score: 70
User: anonymous
Problemset: Croissaria Number
Language: cpp
Time: 1.085 second
Submitted On: 2026-11-01 19:26:42
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
string s;
ll dp[20][2][2][2][11];
int vis[20][2][2][2][11];
int timer = 0;
ll sol(int pos,int ti, int st,int has, int first){
if(pos == (int)s.size()) return (st && has);
if(vis[pos][ti][st][has][first] == timer) return dp[pos][ti][st][has][first];
vis[pos][ti][st][has][first] = timer;
ll &res = dp[pos][ti][st][has][first];
res = 0;
int up = ti ? (s[pos] - '0') : 9;
for(int i=0;i<=up;i++)
{
int n = ti && (i == up);
if(!st){
if (i == 0) res += sol(pos + 1, n, 0, 0, 10);
else res += sol(pos + 1, n, 1, 0, i);
}
else{
if(i < first) res += sol(pos + 1,n, 1, 1, first);
}
}
return res;
}
ll Hippopotomonstrosquipedaliophobia(ll num){
if(num < 10) return 0;
s = to_string(num);
++timer;
return sol(0, 1, 0, 0, 10);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
while (n--){
ll l,r; cin >> l >> r;
cout << Hippopotomonstrosquipedaliophobia(r) - Hippopotomonstrosquipedaliophobia(l-1) << '\n';
}
}