#include <bits/stdc++.h>
using namespace std;
#define long long long
long a, b, pow8[20];
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 all(long x, long y, long k) {
if (!check(x/10)) return 0;
long unit[3];
for (int i=0; i<3; i++) {
unit[i] = y%10;
y /= 10;
}
if (!k) return (unit[0] - (unit[0] > unit[1] && (unit[1] || unit[2])) - (unit[0] > unit[2] && unit[2])) + (unit[0]!=unit[1] && unit[0]!=unit[2]);
return (unit[0] - (unit[0] > unit[1] && (unit[1] || unit[2])) - (unit[0] > unit[2] && unit[2])) * pow8[k-1] * (8 + !(unit[2] + unit[1]));
}
long sol(long a, long b) {
if (a > b) return 0;
if (a == b) return check(a);
if (a < 10 && b < 10) return b-a+1;
long unit_a = 0, unit_b = 0;
while (pow(10, unit_a) <= a) unit_a++;
while (pow(10, unit_b) <= b) unit_b++;
if (unit_a == unit_b && round(a, unit_a-1) == round(b, unit_b-1)) {
long ret = 0, i = 0;
while (b != a) {
ret += all(round(b, 1), b, i);
a /= 10;
b /= 10;
i++;
}
return ret;
}
long ra = round(a, unit_b-1);
long rb = round(b, unit_b-1);
long ret = sol(ra, rb-1) - sol(ra, a) + check(a) + sol(rb, b);
return ret;
}
int main() {
pow8[0] = 1;
for (int i=1; i<=18; i++) pow8[i] = pow8[i-1] * 8;
scanf(" %lld %lld", &a, &b);
printf("%lld", sol(a, b));
}
Compilation message
numbers.cpp: In function 'int main()':
numbers.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | scanf(" %lld %lld", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
12 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Incorrect |
1 ms |
208 KB |
Output isn't correct |
14 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Incorrect |
1 ms |
208 KB |
Output isn't correct |
17 |
Correct |
0 ms |
216 KB |
Output is correct |
18 |
Correct |
1 ms |
216 KB |
Output is correct |
19 |
Correct |
1 ms |
216 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Incorrect |
1 ms |
216 KB |
Output isn't correct |
22 |
Correct |
1 ms |
216 KB |
Output is correct |
23 |
Incorrect |
1 ms |
216 KB |
Output isn't correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
32 |
Correct |
1 ms |
256 KB |
Output is correct |
33 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Incorrect |
1 ms |
224 KB |
Output isn't correct |
36 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
37 |
Incorrect |
0 ms |
204 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 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
44 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
45 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |