# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110712 | ckodser | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 3 ms | 408 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;
const int N = 19;
ll dp[N], dp2[N], dp3[N];
ll Get(ll r)
{
if (r < 0) return (0);
if (r <= 9) return (r + 1);
ll m = r, len = 0;
int A[N];
while (m)
A[len ++] = m % 10, m /= 10;
reverse(A, A + len);
ll res = dp[len - 1];
for (int i = 0; i < len; i++)
{
for (int j = 0; j < A[i]; j++)
{
if (i > 0 && j == A[i - 1])
continue;
if (i > 1 && j == A[i - 2])
continue;
if (i == 0)
res += dp2[len - 1];
else
res += dp3[len - i - 1];
}
if (i > 0 && A[i] == A[i - 1])
return (res);
if (i > 1 && A[i] == A[i - 2])
return (res);
}
if (A[len - 1] != A[len - 2] && (len == 2 || (A[len - 1] != A[len - 3])))
res ++;
return (res);
}
int main()
{
dp[1] = 10;
for (int i = 2; i < N; i++)
dp[i] = dp[i - 1] * 8 + 11;
dp2[0] = 1;
dp2[1] = 9;
for (int i = 2; i < N; i++)
dp2[i] = dp2[i - 1] * 8;
dp3[0] = 1;
dp3[1] = 8;
for (int i = 2; i < N; i++)
dp3[i] = dp3[i - 1] * 8;
ll l, r;
scanf("%lld%lld", &l, &r);
return !printf("%lld\n", Get(r) - Get(l - 1));
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |