-
Notifications
You must be signed in to change notification settings - Fork 2
/
11038.cpp
124 lines (111 loc) · 2.67 KB
/
11038.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//BISMILLAHIRRAHMANIRRAHIM
/*
manus tar shopner soman boro
Author :: Shakil Ahmed
.............AUST_CSE27.........
prob ::
Type ::
verdict::
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <limits.h>
#include <set>
#include <algorithm>
#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <utility>
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define pfcs(cs,a) printf("Case %d: %d\n",cs,a)
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
#define ff first
#define i64 long long
#define ss second
#define rep(i,n) for(i = 0; i < n; i++)
#define REP(i,n) for(i=n;i>=0;i--)
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define ROF(i,a,b) for(int i = a; i >= b; i--)
#define re return
#define QI queue<int>
#define SI stack<int>
#define pii pair <int,int>
#define MAX
#define MOD
#define INF 1<<30
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define memo(a,b) memset((a),(b),sizeof(a))
#define G() getchar()
using namespace std;
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
i64 dp[25][2][2][50],n,str[25];
bool vis[25][2][2][50];
i64 DP(int pos,bool hasSmall,bool start,int count)
{
if(pos==n) return count;
if(vis[pos][hasSmall][start][count]) return dp[pos][hasSmall][start][count];
vis[pos][hasSmall][start][count]=1;
i64 &ret=dp[pos][hasSmall][start][count];
int lim=hasSmall?9:str[pos];
int i;
ret=0;
if(start)
{
for(i=1;i<=lim;i++)
{
ret+=DP(pos+1,hasSmall || (i<lim),0,count+(i==0));
}
ret+=DP(pos+1,1,1,0);
}
else
{
for(i=0;i<=lim;i++)
{
ret+=DP(pos+1,hasSmall || (i<lim),0,count+(i==0));
}
}
return ret;
}
i64 solve(i64 x)
{
i64 y=x;
if(x==-1) return 0;
if(x<10) return 1;
n=0;
while(x)
{
str[n++]=x%10;
x/=10;
}
reverse(str,str+n);
memo(vis,0);
return DP(0,0,1,0)+1;
}
int main()
{
//freopen("in.txt", "r", stdin);
i64 a,b;
while( 1 )
{
scanf("%lld %lld",&a,&b);
if( a < 0 && b < 0 ) break ;
if(a>b) swap(a,b);
printf("%lld\n",solve(b)-solve(a-1));
}
}