#include <bits/stdc++.h>
using namespace std;
#define long long long
const bool debug = 0;
long a, b, pow8[20], dp[20][15][15], d[20][15], sum[20][15];
long round(long x, long k) {
x /= pow(10, k);
return x * pow(10, k);
}
bool check(long x) {
long p = -1, q = -1;
while (x > 0) {
if (x%10 == p || x%10 == q) return false;
q = p;
p = x%10;
x /= 10;
}
return true;
}
long until(long x) {
if (x < 10) return x+1;
int tmp = x;
vector<long> unit;
while (x > 0) unit.push_back(x%10), x/=10;
long ret = sum[unit.size()][unit[unit.size()-1] - 1];
//cout << ret << endl;
for (int j=0; j<unit[unit.size()-2]; j++) {
ret += dp[unit.size()][unit[unit.size()-1]][j];
//cout << unit.size() << ' ' << unit[unit.size()-1] << ' ' << j << ' ' << ret << endl;
}
for (int i=unit.size()-2; i>=1; i--) {
if (!check(tmp / pow(10, i+1))) continue;
for (int j=0; j<unit[i-1]; j++) {
if (j != unit[i+1]) {
ret += dp[i+1][unit[i]][j];
//cout << i+1 << ' ' << unit[i] << ' ' << j << ' ' << ret << endl;
}
}
}
ret += check(tmp);
//cout << ret << endl;
return ret;
}
long sol(long x, long y) {
if (!x) return until(y);
return until(y) - until(x-1);
}
int main() {
pow8[0] = 1;
for (int i=1; i<=18; i++) pow8[i] = pow8[i-1] * 8;
for (int i=0; i<=9; i++) for (int j=0; j<=9; j++) if (i!=j) dp[2][i][j] = 1;
for (int u=3; u<=18; u++) {
for (int i=0; i<=9; i++) {
for (int j=0; j<=9; j++) {
if (i!=j) {
for (int k=0; k<=9; k++) {
if (i!=k && j!=k) dp[u][i][j] += dp[u-1][j][k];
}
}
}
}
}
for (int i=0; i<=9; i++) d[1][i] = 1;
for (int u=2; u<=18; u++) {
for (int i=0; i<=9; i++) {
for (int j=0; j<=9; j++) {
d[u][i] += dp[u][i][j];
}
}
}
sum[1][0] = 1;
for (int u=1; u<=18; u++) {
for (int i=0; i<=9; i++) {
if (!i && u!=1) sum[u][i] = sum[u-1][9];
else sum[u][i] = sum[u][i-1] + d[u][i];
}
}
scanf(" %lld %lld", &a, &b);
printf("%lld", sol(a, b));
}
Compilation message
numbers.cpp: In function 'int main()':
numbers.cpp:85:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | scanf(" %lld %lld", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
8 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
12 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
17 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
20 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
22 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
244 KB |
Output isn't correct |
24 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
26 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
27 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
29 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
30 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
32 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
33 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
34 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
35 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
36 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
37 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
38 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
39 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
40 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
41 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
42 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
43 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
44 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
45 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |