#include <bits/stdc++.h>
using namespace std;
using ll = long long;
string s;
ll dp[19][11][11][2][2][19];
ll f(int p, int L1, int L2, bool U, bool S, int L) {
if(p == s.size()) return 1;
if(dp[p][L1][L2][U][S][L] != -1) return dp[p][L1][L2][U][S][L];
ll ans = 0;
for(int i=0; i<=9; i++) {
if(L >= 1 && i == L1) continue;
if(L >= 2 && i == L2) continue;
if(!U && (i > (s[p] - '0'))) continue;
bool ns = S | (i > 0);
ans += f(p+1, i, L1, U | (i < (s[p] - '0')), ns, L + ns);
}
return dp[p][L1][L2][U][S][L] = ans;
}
ll cnt(ll x) {
s = to_string(x);
memset(dp, -1, sizeof(dp));
return f(0, 10, 10, 0, 0, 0);
}
int main() {
ll l, r;
cin >> l >> r;
cout << cnt(r) - cnt(l-1) << '\n';
return 0;
}
Compilation message
numbers.cpp: In function 'll f(int, int, int, bool, bool, int)':
numbers.cpp:9:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | if(p == s.size()) return 1;
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1628 KB |
Output is correct |
2 |
Correct |
1 ms |
1628 KB |
Output is correct |
3 |
Correct |
2 ms |
1628 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
1 ms |
1720 KB |
Output is correct |
7 |
Correct |
1 ms |
1628 KB |
Output is correct |
8 |
Correct |
1 ms |
1628 KB |
Output is correct |
9 |
Correct |
1 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
1 ms |
1628 KB |
Output is correct |
12 |
Correct |
1 ms |
1628 KB |
Output is correct |
13 |
Correct |
1 ms |
1628 KB |
Output is correct |
14 |
Correct |
1 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
1628 KB |
Output is correct |
16 |
Correct |
1 ms |
1628 KB |
Output is correct |
17 |
Correct |
1 ms |
1628 KB |
Output is correct |
18 |
Correct |
1 ms |
1628 KB |
Output is correct |
19 |
Correct |
2 ms |
1628 KB |
Output is correct |
20 |
Correct |
1 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1796 KB |
Output is correct |
2 |
Correct |
2 ms |
1628 KB |
Output is correct |
3 |
Correct |
3 ms |
1780 KB |
Output is correct |
4 |
Correct |
3 ms |
1784 KB |
Output is correct |
5 |
Correct |
2 ms |
1628 KB |
Output is correct |
6 |
Correct |
1 ms |
1628 KB |
Output is correct |
7 |
Correct |
1 ms |
1628 KB |
Output is correct |
8 |
Correct |
1 ms |
1624 KB |
Output is correct |
9 |
Correct |
1 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
1 ms |
1628 KB |
Output is correct |
12 |
Correct |
1 ms |
1628 KB |
Output is correct |
13 |
Correct |
1 ms |
1628 KB |
Output is correct |
14 |
Correct |
1 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
1880 KB |
Output is correct |
16 |
Correct |
2 ms |
1628 KB |
Output is correct |
17 |
Correct |
2 ms |
1628 KB |
Output is correct |
18 |
Correct |
2 ms |
1628 KB |
Output is correct |
19 |
Correct |
2 ms |
1628 KB |
Output is correct |
20 |
Correct |
2 ms |
1628 KB |
Output is correct |
21 |
Correct |
2 ms |
1628 KB |
Output is correct |
22 |
Correct |
2 ms |
1628 KB |
Output is correct |
23 |
Correct |
2 ms |
1628 KB |
Output is correct |
24 |
Correct |
2 ms |
1628 KB |
Output is correct |
25 |
Correct |
3 ms |
1804 KB |
Output is correct |
26 |
Correct |
2 ms |
1628 KB |
Output is correct |
27 |
Correct |
2 ms |
1628 KB |
Output is correct |
28 |
Correct |
2 ms |
1804 KB |
Output is correct |
29 |
Correct |
2 ms |
1624 KB |
Output is correct |
30 |
Correct |
2 ms |
1628 KB |
Output is correct |
31 |
Correct |
2 ms |
1628 KB |
Output is correct |
32 |
Correct |
3 ms |
1628 KB |
Output is correct |
33 |
Correct |
2 ms |
1628 KB |
Output is correct |
34 |
Correct |
3 ms |
1624 KB |
Output is correct |
35 |
Correct |
2 ms |
1628 KB |
Output is correct |
36 |
Correct |
2 ms |
1628 KB |
Output is correct |
37 |
Correct |
2 ms |
1628 KB |
Output is correct |
38 |
Correct |
2 ms |
1624 KB |
Output is correct |
39 |
Correct |
3 ms |
1624 KB |
Output is correct |
40 |
Correct |
2 ms |
1880 KB |
Output is correct |
41 |
Correct |
2 ms |
1628 KB |
Output is correct |
42 |
Correct |
2 ms |
1624 KB |
Output is correct |
43 |
Correct |
2 ms |
1628 KB |
Output is correct |
44 |
Correct |
2 ms |
1628 KB |
Output is correct |
45 |
Correct |
2 ms |
1628 KB |
Output is correct |