#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
int k;
long long l, r;
long long dp[50][15][15][5][5][2];
vector<int> digitl;
vector<int> digitr;
long long solve (int cur, int last1, int last2, bool low, bool high, bool ok)
{
//if (last1>=0&&last2>=0)
if (dp[cur][last1][last2][low][high][ok]!=-1) return dp[cur][last1][last2][low][high][ok];
if (cur==k) return 1ll;
long long cnt=0ll;
for (int i=0; i<10; i++)
if (i!=last1&&i!=last2&&(low||i>=digitl[cur])&&(high||i<=digitr[cur]))
cnt+=solve(cur+1, (!ok&&i<1?10:i), last1, low||i>digitl[cur], high||i<digitr[cur], ok||(i>0));
dp[cur][last1][last2][low][high][ok]=cnt;
return cnt;
}
int main()
{
//freopen("numbers.inp", "r", stdin);
//freopen("numbers.out", "w", stdout);
cin>>l>>r;
while (l>0)
digitl.push_back(l%10ll), l/=10ll;
while (r>0)
digitr.push_back(r%10ll), r/=10ll;
while ((int)digitl.size()<(int)digitr.size()) digitl.push_back(0);
while ((int)digitr.size()<(int)digitl.size()) digitr.push_back(0);
k=(int)digitr.size();
reverse(digitl.begin(), digitl.end());
reverse(digitr.begin(), digitr.end());
memset(dp, -1, sizeof dp);
cout<<solve(0, 10, 10, 0, 0, 0);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4856 KB |
Output is correct |
2 |
Correct |
6 ms |
4860 KB |
Output is correct |
3 |
Correct |
6 ms |
4924 KB |
Output is correct |
4 |
Correct |
6 ms |
5060 KB |
Output is correct |
5 |
Correct |
5 ms |
5064 KB |
Output is correct |
6 |
Correct |
5 ms |
5064 KB |
Output is correct |
7 |
Correct |
5 ms |
5064 KB |
Output is correct |
8 |
Correct |
5 ms |
5076 KB |
Output is correct |
9 |
Correct |
5 ms |
5076 KB |
Output is correct |
10 |
Correct |
5 ms |
5128 KB |
Output is correct |
11 |
Correct |
5 ms |
5128 KB |
Output is correct |
12 |
Correct |
5 ms |
5128 KB |
Output is correct |
13 |
Correct |
5 ms |
5128 KB |
Output is correct |
14 |
Correct |
5 ms |
5128 KB |
Output is correct |
15 |
Correct |
5 ms |
5128 KB |
Output is correct |
16 |
Correct |
7 ms |
5168 KB |
Output is correct |
17 |
Correct |
5 ms |
5324 KB |
Output is correct |
18 |
Correct |
5 ms |
5324 KB |
Output is correct |
19 |
Correct |
6 ms |
5324 KB |
Output is correct |
20 |
Correct |
7 ms |
5324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
5360 KB |
Output is correct |
2 |
Correct |
6 ms |
5360 KB |
Output is correct |
3 |
Correct |
6 ms |
5360 KB |
Output is correct |
4 |
Correct |
5 ms |
5360 KB |
Output is correct |
5 |
Correct |
6 ms |
5404 KB |
Output is correct |
6 |
Correct |
5 ms |
5404 KB |
Output is correct |
7 |
Correct |
5 ms |
5404 KB |
Output is correct |
8 |
Correct |
5 ms |
5404 KB |
Output is correct |
9 |
Correct |
5 ms |
5404 KB |
Output is correct |
10 |
Correct |
5 ms |
5404 KB |
Output is correct |
11 |
Correct |
6 ms |
5404 KB |
Output is correct |
12 |
Correct |
5 ms |
5404 KB |
Output is correct |
13 |
Correct |
5 ms |
5404 KB |
Output is correct |
14 |
Correct |
5 ms |
5404 KB |
Output is correct |
15 |
Correct |
5 ms |
5404 KB |
Output is correct |
16 |
Correct |
5 ms |
5404 KB |
Output is correct |
17 |
Correct |
5 ms |
5404 KB |
Output is correct |
18 |
Correct |
5 ms |
5404 KB |
Output is correct |
19 |
Correct |
5 ms |
5404 KB |
Output is correct |
20 |
Correct |
5 ms |
5404 KB |
Output is correct |
21 |
Correct |
5 ms |
5404 KB |
Output is correct |
22 |
Correct |
5 ms |
5404 KB |
Output is correct |
23 |
Correct |
6 ms |
5404 KB |
Output is correct |
24 |
Correct |
5 ms |
5404 KB |
Output is correct |
25 |
Correct |
6 ms |
5404 KB |
Output is correct |
26 |
Correct |
6 ms |
5404 KB |
Output is correct |
27 |
Correct |
6 ms |
5404 KB |
Output is correct |
28 |
Correct |
6 ms |
5404 KB |
Output is correct |
29 |
Correct |
5 ms |
5404 KB |
Output is correct |
30 |
Correct |
5 ms |
5404 KB |
Output is correct |
31 |
Correct |
6 ms |
5404 KB |
Output is correct |
32 |
Correct |
6 ms |
5404 KB |
Output is correct |
33 |
Correct |
7 ms |
5404 KB |
Output is correct |
34 |
Correct |
6 ms |
5404 KB |
Output is correct |
35 |
Correct |
6 ms |
5404 KB |
Output is correct |
36 |
Correct |
5 ms |
5412 KB |
Output is correct |
37 |
Correct |
6 ms |
5412 KB |
Output is correct |
38 |
Correct |
6 ms |
5416 KB |
Output is correct |
39 |
Correct |
6 ms |
5504 KB |
Output is correct |
40 |
Correct |
7 ms |
5504 KB |
Output is correct |
41 |
Correct |
6 ms |
5504 KB |
Output is correct |
42 |
Correct |
5 ms |
5504 KB |
Output is correct |
43 |
Correct |
6 ms |
5504 KB |
Output is correct |
44 |
Correct |
6 ms |
5504 KB |
Output is correct |
45 |
Correct |
6 ms |
5508 KB |
Output is correct |