# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
284639 | ChrisT | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 1 ms | 512 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;
const int MN = 1e3 + 5;
long long dp[2][20][10][10]; //dp[<=][digit][last digit][2nd last digit]
long long solve (long long x) {
long long ret = 0; memset(dp,0,sizeof dp);
for (int i = 0; i < min(100LL,x+1); i++) if (i < 10 || i/10 != i%10){
++ret;
dp[0][0][i/10][i%10] = 1;
if (i <= x % 100) dp[1][0][i/10][i%10] = 1;
}
if (x<100) return ret;
x /= 100;
for (int i = 1; x; i++, x /= 10) {
for (int take = 0; take < 10; take++) {
for (int lst = 0; lst < 10; lst++) if (lst != take) {
for (int bef = 0; bef < 10; bef++) if (lst != bef && bef != take) {
dp[0][i][take][lst] += dp[0][i-1][lst][bef];
if (take == x%10) dp[1][i][take][lst] += dp[1][i-1][lst][bef];
else if (take < x%10) dp[1][i][take][lst] += dp[0][i-1][lst][bef];
}
if (!take) continue;
if (x>=10) ret += dp[0][i][take][lst];
else ret += dp[1][i][take][lst];
}
}
}
return ret;
}
int main () {
long long a,b;
scanf ("%lld %lld",&a,&b);
printf ("%lld\n",solve(b) - solve(a-1));
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |