#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXL = 25;
const int MAXD = 12;
ll dp[MAXL][MAXD][MAXD][2][2];
vector<int> digitos;
int N;
ll A,B;
ll solve(int pos,int l1,int l2,int flag,int leading){
ll &ret = dp[pos][l1][l2][flag][leading];
if(ret != -1) return ret;
ret = 0;
if(pos == N){
ret = 1;
return ret;
}
int limite = 9;
if(flag) limite = digitos[pos];
for(int i = 0;i<=limite;i++){
if(leading == 1 && i == 0){
ret += solve(pos+1,l1,l2,flag && (i == limite),leading);
}
else{
if(l1 != i && l2 != i) ret += solve(pos+1,i,l1,flag && (i == limite), 0);
}
}
return ret;
}
ll calcula(ll X){
if(X == -1) return 0;
if(X == 0) return 1;
digitos.clear();
memset(dp,-1,sizeof(dp));
while(X != 0){
digitos.push_back(X % 10);
X /= 10;
}
reverse(digitos.begin(),digitos.end());
N = digitos.size();
return solve(0,10,10,1,1);
}
int main(){
cin >> A >> B;
cout << calcula(B) - calcula(A-1) << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
532 KB |
Output is correct |
3 |
Correct |
3 ms |
544 KB |
Output is correct |
4 |
Correct |
3 ms |
544 KB |
Output is correct |
5 |
Correct |
3 ms |
568 KB |
Output is correct |
6 |
Correct |
2 ms |
700 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
3 ms |
760 KB |
Output is correct |
9 |
Correct |
3 ms |
760 KB |
Output is correct |
10 |
Correct |
3 ms |
760 KB |
Output is correct |
11 |
Correct |
3 ms |
760 KB |
Output is correct |
12 |
Correct |
3 ms |
760 KB |
Output is correct |
13 |
Correct |
3 ms |
764 KB |
Output is correct |
14 |
Correct |
2 ms |
768 KB |
Output is correct |
15 |
Correct |
3 ms |
768 KB |
Output is correct |
16 |
Correct |
3 ms |
776 KB |
Output is correct |
17 |
Correct |
4 ms |
784 KB |
Output is correct |
18 |
Correct |
3 ms |
784 KB |
Output is correct |
19 |
Correct |
3 ms |
788 KB |
Output is correct |
20 |
Correct |
3 ms |
788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
796 KB |
Output is correct |
2 |
Correct |
4 ms |
800 KB |
Output is correct |
3 |
Correct |
3 ms |
804 KB |
Output is correct |
4 |
Correct |
3 ms |
808 KB |
Output is correct |
5 |
Correct |
2 ms |
812 KB |
Output is correct |
6 |
Correct |
3 ms |
816 KB |
Output is correct |
7 |
Correct |
2 ms |
820 KB |
Output is correct |
8 |
Correct |
3 ms |
824 KB |
Output is correct |
9 |
Correct |
3 ms |
828 KB |
Output is correct |
10 |
Correct |
2 ms |
832 KB |
Output is correct |
11 |
Correct |
4 ms |
836 KB |
Output is correct |
12 |
Correct |
4 ms |
968 KB |
Output is correct |
13 |
Correct |
2 ms |
968 KB |
Output is correct |
14 |
Correct |
2 ms |
968 KB |
Output is correct |
15 |
Correct |
3 ms |
968 KB |
Output is correct |
16 |
Correct |
3 ms |
968 KB |
Output is correct |
17 |
Correct |
4 ms |
968 KB |
Output is correct |
18 |
Correct |
3 ms |
968 KB |
Output is correct |
19 |
Correct |
4 ms |
968 KB |
Output is correct |
20 |
Correct |
3 ms |
968 KB |
Output is correct |
21 |
Correct |
5 ms |
968 KB |
Output is correct |
22 |
Correct |
3 ms |
968 KB |
Output is correct |
23 |
Correct |
4 ms |
968 KB |
Output is correct |
24 |
Correct |
3 ms |
968 KB |
Output is correct |
25 |
Correct |
3 ms |
968 KB |
Output is correct |
26 |
Correct |
3 ms |
968 KB |
Output is correct |
27 |
Correct |
5 ms |
968 KB |
Output is correct |
28 |
Correct |
3 ms |
968 KB |
Output is correct |
29 |
Correct |
4 ms |
968 KB |
Output is correct |
30 |
Correct |
3 ms |
968 KB |
Output is correct |
31 |
Correct |
3 ms |
968 KB |
Output is correct |
32 |
Correct |
3 ms |
968 KB |
Output is correct |
33 |
Correct |
3 ms |
968 KB |
Output is correct |
34 |
Correct |
3 ms |
968 KB |
Output is correct |
35 |
Correct |
3 ms |
968 KB |
Output is correct |
36 |
Correct |
3 ms |
968 KB |
Output is correct |
37 |
Correct |
3 ms |
968 KB |
Output is correct |
38 |
Correct |
4 ms |
968 KB |
Output is correct |
39 |
Correct |
3 ms |
968 KB |
Output is correct |
40 |
Correct |
3 ms |
972 KB |
Output is correct |
41 |
Correct |
3 ms |
972 KB |
Output is correct |
42 |
Correct |
3 ms |
980 KB |
Output is correct |
43 |
Correct |
2 ms |
984 KB |
Output is correct |
44 |
Correct |
3 ms |
988 KB |
Output is correct |
45 |
Correct |
4 ms |
992 KB |
Output is correct |