#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int dp[20][11][11][2][2];
ll solve(vi&a,int i,int l1,int l2,int tight,int started)
{
if (dp[i][l1][l2][tight][started] != 0)return dp[i][l1][l2][tight][started];
if (i == (int)a.size())return 1;
if (tight){
for (int j = 0;j<a[i];j++){
if (l1 == j || l2 == j)continue;
if (started || j != 0)dp[i][l1][l2][1][started] += solve(a,i + 1,j,l1,0,1);
else dp[i][l1][l2][1][started] += solve(a,i + 1,10,l1,0,0);
}
if (l1 != a[i] && l2 != a[i]){
if (started || a[i] != 0)dp[i][l1][l2][tight][started] += solve(a,i + 1,a[i],l1,1,1);
else dp[i][l1][l2][1][started] += solve(a,i + 1,10,l1,1,0);
}
}
else{
for (int j = 0;j<=9;j++){
if (l1 == j || l2 == j)continue;
if (started || j != 0)dp[i][l1][l2][tight][started] += solve(a,i + 1,j,l1,0,1);
else dp[i][l1][l2][0][started] += solve(a,i + 1,10,l1,0,0);
}
}
return dp[i][l1][l2][tight][started];
}
int main()
{
ll a,b;
cin>>a>>b;
if (b == 0){cout<<1;return 0;}
vi diga,digb;
a--;
while (a > 0){diga.pb(a%10);a/=10;}
while (b > 0){digb.pb(b%10);b/=10;}
if (!diga.empty())reverse(diga.begin(),diga.end());
reverse(digb.begin(),digb.end());
ll ans = 0;
if (!diga.empty())ans = solve(diga,0,10,10,1,0);
memset(dp,0,sizeof(dp));
ans = -ans + solve(digb,0,10,10,1,0);
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
3 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Incorrect |
4 ms |
364 KB |
Output isn't correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
4 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
74 ms |
364 KB |
Output isn't correct |
3 |
Incorrect |
12 ms |
364 KB |
Output isn't correct |
4 |
Incorrect |
62 ms |
364 KB |
Output isn't correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
15 ms |
364 KB |
Output is correct |
17 |
Correct |
53 ms |
364 KB |
Output is correct |
18 |
Correct |
37 ms |
364 KB |
Output is correct |
19 |
Correct |
55 ms |
364 KB |
Output is correct |
20 |
Correct |
79 ms |
492 KB |
Output is correct |
21 |
Incorrect |
13 ms |
364 KB |
Output isn't correct |
22 |
Correct |
3 ms |
364 KB |
Output is correct |
23 |
Incorrect |
74 ms |
364 KB |
Output isn't correct |
24 |
Correct |
61 ms |
364 KB |
Output is correct |
25 |
Incorrect |
67 ms |
364 KB |
Output isn't correct |
26 |
Incorrect |
12 ms |
364 KB |
Output isn't correct |
27 |
Incorrect |
48 ms |
492 KB |
Output isn't correct |
28 |
Incorrect |
73 ms |
496 KB |
Output isn't correct |
29 |
Correct |
12 ms |
384 KB |
Output is correct |
30 |
Correct |
31 ms |
364 KB |
Output is correct |
31 |
Incorrect |
12 ms |
364 KB |
Output isn't correct |
32 |
Correct |
45 ms |
364 KB |
Output is correct |
33 |
Incorrect |
4 ms |
364 KB |
Output isn't correct |
34 |
Correct |
43 ms |
364 KB |
Output is correct |
35 |
Incorrect |
47 ms |
364 KB |
Output isn't correct |
36 |
Incorrect |
12 ms |
364 KB |
Output isn't correct |
37 |
Incorrect |
12 ms |
364 KB |
Output isn't correct |
38 |
Incorrect |
60 ms |
364 KB |
Output isn't correct |
39 |
Incorrect |
62 ms |
364 KB |
Output isn't correct |
40 |
Correct |
20 ms |
408 KB |
Output is correct |
41 |
Incorrect |
13 ms |
364 KB |
Output isn't correct |
42 |
Correct |
53 ms |
364 KB |
Output is correct |
43 |
Incorrect |
53 ms |
364 KB |
Output isn't correct |
44 |
Incorrect |
77 ms |
364 KB |
Output isn't correct |
45 |
Incorrect |
73 ms |
492 KB |
Output isn't correct |