#include <stdio.h>
bool check[11][11][20];
long long d[11][11][20];
long long f(int x, int y, int len) {
if (x == 10 && y == 10 && len == 0) return 0;
// if (x == 10 && y == 10 && len == 1) return 8;
if (len == 0) return 1;
if (!check[x][y][len]) {
check[x][y][len] = true;
if (x == 10 && y == 10) {
for (int i = 1; i < 10; i++) d[x][y][len] += f(10, i, len - 1);
d[x][y][len] += f(10, 10, len - 1);
}
else if (x == 10) {
for (int i = 0; i < 10; i++)
if (i != y) d[x][y][len] += f(y, i, len - 1);
}
else {
for (int i = 0; i < 10; i++) {
if (i == x || i == y) continue;
d[x][y][len] += f(y, i, len - 1);
}
}
} return d[x][y][len];
}
long long out(long long x) {
long long sum = 0, check_m;
int len = 0, temp[19] = { 0 }, in[19] = { 0 };
while (x) temp[++len] = x % 10, x /= 10;
for (int i = 1; i <= len; i++) in[len - i + 1] = temp[i];
in[0] = 10;
for (int i = len; i >= 2; i--) {
check_m = 1;
for (int j = 2; j < i; j++)
if (in[j - 2] == in[j] || in[j - 1] == in[j]) check_m = 0;
for (int j = 0; j < in[i]; j++)
if (j != in[i - 1] && j != in[i - 2]) sum += f(in[i - 1], j, len - i)*check_m;
}
for (int i = 1; i < in[1]; i++) sum += f(10, i, len - 1);
sum += f(10, 10, len - 1);
check_m = 1;
for (int j = 2; j <=len; j++)
if (in[j - 2] == in[j] || in[j - 1] == in[j]) check_m = 0;
return sum + check_m;
}
int main() {
long long x, y, sum;
scanf("%lld %lld", &x, &y);
if (!x) x++;
sum = out(y);
if (x >= 10) sum -= out(x - 1);
else sum -= x;
printf("%lld", sum);
}
Compilation message
numbers.cpp: In function 'int main()':
numbers.cpp:60:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &x, &y);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
1132 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
1132 KB |
Output isn't correct |
3 |
Correct |
0 ms |
1132 KB |
Output is correct |
4 |
Incorrect |
0 ms |
1132 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
1132 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
1132 KB |
Output isn't correct |
7 |
Incorrect |
0 ms |
1132 KB |
Output isn't correct |
8 |
Incorrect |
0 ms |
1132 KB |
Output isn't correct |
9 |
Correct |
0 ms |
1132 KB |
Output is correct |
10 |
Correct |
0 ms |
1132 KB |
Output is correct |
11 |
Correct |
0 ms |
1132 KB |
Output is correct |
12 |
Correct |
0 ms |
1132 KB |
Output is correct |
13 |
Correct |
0 ms |
1132 KB |
Output is correct |
14 |
Incorrect |
0 ms |
1132 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
1132 KB |
Output isn't correct |
16 |
Correct |
0 ms |
1132 KB |
Output is correct |
17 |
Correct |
0 ms |
1132 KB |
Output is correct |
18 |
Runtime error |
0 ms |
2828 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Correct |
0 ms |
1132 KB |
Output is correct |
20 |
Correct |
0 ms |
1132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1132 KB |
Output is correct |
2 |
Correct |
0 ms |
1132 KB |
Output is correct |
3 |
Correct |
0 ms |
1132 KB |
Output is correct |
4 |
Correct |
0 ms |
1132 KB |
Output is correct |
5 |
Correct |
0 ms |
1132 KB |
Output is correct |
6 |
Correct |
0 ms |
1132 KB |
Output is correct |
7 |
Correct |
0 ms |
1132 KB |
Output is correct |
8 |
Correct |
0 ms |
1132 KB |
Output is correct |
9 |
Correct |
0 ms |
1132 KB |
Output is correct |
10 |
Correct |
0 ms |
1132 KB |
Output is correct |
11 |
Correct |
0 ms |
1132 KB |
Output is correct |
12 |
Correct |
0 ms |
1132 KB |
Output is correct |
13 |
Correct |
0 ms |
1132 KB |
Output is correct |
14 |
Correct |
0 ms |
1132 KB |
Output is correct |
15 |
Correct |
0 ms |
1132 KB |
Output is correct |
16 |
Correct |
0 ms |
1132 KB |
Output is correct |
17 |
Correct |
0 ms |
1132 KB |
Output is correct |
18 |
Correct |
0 ms |
1132 KB |
Output is correct |
19 |
Correct |
0 ms |
1132 KB |
Output is correct |
20 |
Correct |
0 ms |
1132 KB |
Output is correct |
21 |
Correct |
0 ms |
1132 KB |
Output is correct |
22 |
Correct |
0 ms |
1132 KB |
Output is correct |
23 |
Correct |
0 ms |
1132 KB |
Output is correct |
24 |
Correct |
0 ms |
1132 KB |
Output is correct |
25 |
Correct |
0 ms |
1132 KB |
Output is correct |
26 |
Correct |
0 ms |
1132 KB |
Output is correct |
27 |
Correct |
0 ms |
1132 KB |
Output is correct |
28 |
Correct |
0 ms |
1132 KB |
Output is correct |
29 |
Correct |
0 ms |
1132 KB |
Output is correct |
30 |
Correct |
0 ms |
1132 KB |
Output is correct |
31 |
Correct |
0 ms |
1132 KB |
Output is correct |
32 |
Correct |
0 ms |
1132 KB |
Output is correct |
33 |
Correct |
0 ms |
1132 KB |
Output is correct |
34 |
Correct |
0 ms |
1132 KB |
Output is correct |
35 |
Correct |
0 ms |
1132 KB |
Output is correct |
36 |
Correct |
0 ms |
1132 KB |
Output is correct |
37 |
Correct |
0 ms |
1132 KB |
Output is correct |
38 |
Correct |
0 ms |
1132 KB |
Output is correct |
39 |
Correct |
0 ms |
1132 KB |
Output is correct |
40 |
Correct |
0 ms |
1132 KB |
Output is correct |
41 |
Correct |
0 ms |
1132 KB |
Output is correct |
42 |
Correct |
0 ms |
1132 KB |
Output is correct |
43 |
Correct |
0 ms |
1132 KB |
Output is correct |
44 |
Correct |
0 ms |
1132 KB |
Output is correct |
45 |
Correct |
0 ms |
1132 KB |
Output is correct |