#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<ll, ll>
#define to second
#define cost first
typedef long long ll;
typedef long double ld;
using namespace std;
std::vector<int> num;
int dp[20][10][10][2][2];
int answer(int idx, int a, int b, int noconst, int start) {
if(idx == (int)num.size()) return 1;
if(dp[idx][a][b][noconst][start] != -1) return dp[idx][a][b][noconst][start];
int ret = 0, limit;
if(noconst) limit = 9; else limit = num[idx];
for(int i = 0; i <= limit; i++) {
if(i == a || i == b) continue;
if(i == 0 && start == 0) ret += answer(idx+1, 10, 10, 1, 0);
else ret += answer(idx+1, b, i, noconst | (i < num[idx]), 1);
} return dp[idx][a][b][noconst][start] = ret;
}
int solve(ll n) {
//if(n < 0) return 0;
//if(n < 10) return n+1;
num.clear();
while(n) {
num.pb(n%10);
n /= 10;
}
reverse(num.begin(), num.end());
memset(dp, -1, sizeof dp);
return answer(0, 10, 10, 0, 0);
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
ll a, b;
cin >> a >> b;
ll ans = solve(b);
ans -= solve(a-1);
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
512 KB |
Output is correct |
14 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
16 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
17 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
20 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
3 ms |
256 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
8 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
14 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
15 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
16 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
24 |
Correct |
4 ms |
384 KB |
Output is correct |
25 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
26 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
27 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
28 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
29 |
Correct |
2 ms |
356 KB |
Output is correct |
30 |
Correct |
3 ms |
384 KB |
Output is correct |
31 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
32 |
Correct |
3 ms |
384 KB |
Output is correct |
33 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
36 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
37 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
38 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
39 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
40 |
Correct |
2 ms |
384 KB |
Output is correct |
41 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
42 |
Correct |
3 ms |
384 KB |
Output is correct |
43 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
44 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
45 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |