# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
563441 | tht2005 | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 1 ms | 464 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
char a[20];
LL f[20][2][11][11];
LL calc(LL x) {
sprintf(a, "%lld", x);
int n = strlen(a);
for(int i = 0; i <= n; ++i) {
memset(f[i], 0, sizeof(f[i]));
}
f[0][0][10][10] = 1;
for(int i = 0; i < n; ++i) {
for(int t = 0; t < 2; ++t) {
for(int j = 0; j < 11; ++j) {
for(int k = 0; k < 11; ++k) {
LL ft = f[i][t][j][k];
if(ft == 0) continue;
if(k == 10) f[i + 1][1][10][10] += ft;
for(int c = (k == 10); t ? (c < 10) : (c <= a[i] - '0'); ++c) {
if(c == j || c == k) continue;
f[i + 1][t || (c < a[i] - '0')][k][c] += ft;
}
}
}
}
}
LL res = 0;
for(int i = 0; i < 11; ++i) {
for(int j = 0; j < 11; ++j) {
res += f[n][1][i][j];
}
}
return res;
}
int main() {
LL l, r;
scanf("%lld %lld", &l, &r);
printf("%lld", calc(r + 1) - calc(l) + (l == 0));
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |