//
// Created by Le Gia Khanh
//
/* pray for luck UwU
_
ooOoo
o8888888o
88" . "88
(| -_- |)
O\ = /O
___/`---'\___
.' \| |// `.
/ \||| : |||// \
/ ||||| -:- ||||| \
| | \ - /'| | |
| \_| `\`---'// |_/ |
\ .-\__ `-. -'__/-. /
___. .' /--.--\ . .'___
."" '< `.___\_<|>_/___.' _> \"".
| | : - \. ;`. _/; .'/ / .' ; |
\ \ -. \_\_. _.'_/_/ -' _.' /
===========`-.`___`-.__\ \___ /__.-'.'.-'================
`=--=-' hjw
*/
#include <bits/stdc++.h>
using namespace std;
#define div awfiuskjdnvknj
#define fi first
#define pb push_back
#define mp make_pair
#define TASK "TASK"
#define se second
#define timeclock printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC);
// 1 << __builtin_ctz(x). Compute the biggest power of 2 that is a divisor of x. Example: f(12) = 4
#define builtin_ctz __builtin_ctz
// 1 << (32 - __builtin_clz (x - 1)) Compute the smallest power of 2 that is not smaller than x. Example: f(12) = 16
#define builtin_clz builtin_clz
//count bit 1
#define __builtin_popcount __builtin_popcountll
template<class X, class Y>
bool minimize(X &x, const Y &y) {
X eps = 1e-9;
if (x > y + eps) {
x = y;
return true;
} else return false;
}
template<class X, class Y>
bool maximize(X &x, const Y &y) {
X eps = 1e-9;
if (x + eps < y) {
x = y;
return true;
} else return false;
}
long long dp[20][11][11][2][2];
long long solve(bool ok, bool flag, int cur, int pre1, int pre2, string x){
if (cur == x.size()){
// cout << trace << "\n";
return 1;
}
if (dp[cur][pre1][pre2][ok][flag] != -1)
return dp[cur][pre1][pre2][ok][flag];
int m = ok ? x[cur] - '0' : 9;
long long res = 0;
for (int i = 0; i <= m; i++){
if (pre1 == i || pre2 == i)
continue;
int new_flag = flag && i == 0;
int new_pre1 = 10, new_pre2 = 10;
if (!new_flag)
new_pre1 = pre2,
new_pre2 = i;
res += solve(ok & (i == m), new_flag, cur + 1, new_pre1, new_pre2, x);
}
return dp[cur][pre1][pre2][ok][flag] = res;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
long long a, b;
cin >> a >> b;
memset(dp, -1, sizeof dp);
long long L = solve(1, 1, 0, 10, 10, to_string(a - 1));
memset(dp, -1, sizeof dp);
long long R = solve(1, 1, 0, 10, 10, to_string(b));
cout << R - L;
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
// #ifdef ONLINE_JUDGE
// freopen("input.inp", "r", stdin);
// freopen("output.out", "w", stdout);
// #endif
Compilation message
numbers.cpp: In function 'long long int solve(bool, bool, int, int, int, std::string)':
numbers.cpp:68:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | if (cur == x.size()){
| ~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
2 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
336 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
316 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
2 ms |
324 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
2 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
2 ms |
336 KB |
Output is correct |
33 |
Correct |
2 ms |
336 KB |
Output is correct |
34 |
Correct |
2 ms |
392 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
2 ms |
336 KB |
Output is correct |
37 |
Correct |
2 ms |
320 KB |
Output is correct |
38 |
Correct |
2 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
2 ms |
464 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
316 KB |
Output is correct |
45 |
Correct |
1 ms |
320 KB |
Output is correct |