#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a, b, dp[20][11][11][11];
vector<ll> get_digits(ll k) {
vector<ll> ret;
ll len = log10(k) + 1;
for(int i = 0; i < len; i++) {
ret.push_back(k % 10);
k /= 10;
}
reverse(ret.begin(), ret.end());
return ret;
}
ll pf_leq(ll k) {
if(k <= 9) return k+1;
ll len = log10(k)+1;
vector<ll> digits = get_digits(k);
memset(dp, 0, sizeof(dp));
for(int p0 = 0; p0 <= 9; p0++) dp[len-1][p0][10][10] = 1;
for(int i = len-2; i >= 0; i--) {
for(int p0 = 0; p0 <= 9; p0++) {
for(int p1 = 0; p1 <= 9; p1++) if(p0 != p1) {
if(i+2 < len) {
for(int p2 = 0; p2 <= 9; p2++) if(p2 != p1 && p2 != p0) {
if(i+3 < len) for(int p3 = 0; p3 <= 9; p3++) {
dp[i][p0][p1][p2] += dp[i+1][p1][p2][p3];
} else {
dp[i][p0][p1][p2] += dp[i+1][p1][p2][10];
}
// cout << i << ' ' << p0 << ' ' << p1 << ' ' << p2 << ' ' << dp[i][p0][p1][p2] << endl;
}
} else {
dp[i][p0][p1][10] += dp[i+1][p1][10][10];
}
}
}
}
ll ret = 0;
// cout << digits[0] << endl;
for(int i = 0; i < len; i++) {
if((i >= 2 && digits[i-1] == digits[i-2]) || (i >= 3 && digits[i-1] == digits[i-3])) break;
for(int p0 = (i == 0); p0 <= (i == len-1 ? digits[i] : digits[i]-1); p0++) if((i == 0 || p0 != digits[i-1]) && (i <= 1 || p0 != digits[i-2])) {
for(int p1 = 0; p1 <= 10; p1++) if(p1 != p0 && (i == 0 || p1 != digits[i-1])) {
for(int p2 = 0; p2 <= 10; p2++) if((i == len-1 || p2 != p1) && p2 != p0) {
ret += dp[i][p0][p1][p2];
// cout << i << ' ' << p0 << ' ' << p1 << ' ' << p2 << ' ' << dp[i][p0][p1][p2] << endl;
}
}
}
}
// cout << ret << endl;
return ret;
}
int main() {
// int cnt = 0;
// for(int i = 1000; i <= 1100; i++) {
// vector<ll> digits = get_digits(i);
// cnt += digits[0] != digits[1] && digits[1] != digits[2] && digits[0] != digits[2];
// cout << i << ' ' << pf_leq(i) << ' ' << cnt << endl;
// }
cin >> a >> b;
ll pa = log10(a-1), pb = log10(b);
ll curra = 1, currb = 1;
ll resa = 0, resb = 0;
for(int i = 1; i <= pa; i++) resa += pf_leq(curra-1);
for(int i = 1; i <= pb; i++) resb += pf_leq(currb-1);
resa += pf_leq(a-1);
resb += pf_leq(b);
cout << resb - resa;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
612 KB |
Output isn't correct |
3 |
Correct |
2 ms |
844 KB |
Output is correct |
4 |
Incorrect |
2 ms |
844 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
844 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
844 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
928 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
928 KB |
Output isn't correct |
9 |
Correct |
2 ms |
928 KB |
Output is correct |
10 |
Correct |
2 ms |
928 KB |
Output is correct |
11 |
Correct |
2 ms |
928 KB |
Output is correct |
12 |
Correct |
2 ms |
928 KB |
Output is correct |
13 |
Correct |
2 ms |
928 KB |
Output is correct |
14 |
Incorrect |
2 ms |
928 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
928 KB |
Output isn't correct |
16 |
Correct |
2 ms |
928 KB |
Output is correct |
17 |
Correct |
2 ms |
928 KB |
Output is correct |
18 |
Correct |
2 ms |
928 KB |
Output is correct |
19 |
Correct |
2 ms |
928 KB |
Output is correct |
20 |
Incorrect |
2 ms |
928 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
928 KB |
Output is correct |
2 |
Correct |
2 ms |
928 KB |
Output is correct |
3 |
Correct |
2 ms |
928 KB |
Output is correct |
4 |
Correct |
2 ms |
928 KB |
Output is correct |
5 |
Incorrect |
2 ms |
928 KB |
Output isn't correct |
6 |
Correct |
2 ms |
932 KB |
Output is correct |
7 |
Incorrect |
2 ms |
936 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
940 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
996 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
996 KB |
Output isn't correct |
11 |
Correct |
2 ms |
996 KB |
Output is correct |
12 |
Incorrect |
2 ms |
996 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
996 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
996 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
996 KB |
Output isn't correct |
16 |
Correct |
2 ms |
1044 KB |
Output is correct |
17 |
Correct |
2 ms |
1044 KB |
Output is correct |
18 |
Correct |
2 ms |
1044 KB |
Output is correct |
19 |
Correct |
2 ms |
1044 KB |
Output is correct |
20 |
Correct |
2 ms |
1044 KB |
Output is correct |
21 |
Correct |
2 ms |
1044 KB |
Output is correct |
22 |
Correct |
2 ms |
1044 KB |
Output is correct |
23 |
Correct |
2 ms |
1044 KB |
Output is correct |
24 |
Correct |
2 ms |
1044 KB |
Output is correct |
25 |
Correct |
3 ms |
1044 KB |
Output is correct |
26 |
Correct |
2 ms |
1044 KB |
Output is correct |
27 |
Correct |
2 ms |
1044 KB |
Output is correct |
28 |
Correct |
2 ms |
1044 KB |
Output is correct |
29 |
Correct |
2 ms |
1044 KB |
Output is correct |
30 |
Correct |
2 ms |
1044 KB |
Output is correct |
31 |
Correct |
2 ms |
1048 KB |
Output is correct |
32 |
Correct |
2 ms |
1052 KB |
Output is correct |
33 |
Correct |
2 ms |
1056 KB |
Output is correct |
34 |
Correct |
3 ms |
1060 KB |
Output is correct |
35 |
Correct |
2 ms |
1064 KB |
Output is correct |
36 |
Correct |
2 ms |
1068 KB |
Output is correct |
37 |
Correct |
2 ms |
1072 KB |
Output is correct |
38 |
Correct |
2 ms |
1076 KB |
Output is correct |
39 |
Correct |
2 ms |
1080 KB |
Output is correct |
40 |
Correct |
2 ms |
1132 KB |
Output is correct |
41 |
Correct |
3 ms |
1132 KB |
Output is correct |
42 |
Correct |
2 ms |
1132 KB |
Output is correct |
43 |
Correct |
2 ms |
1132 KB |
Output is correct |
44 |
Correct |
2 ms |
1132 KB |
Output is correct |
45 |
Correct |
2 ms |
1132 KB |
Output is correct |