| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1120860 | vjudge1 | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 2 ms | 516 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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T, typename key = less_equal<T>>
using ordered_set = tree<T, null_type, key, rb_tree_tag, tree_order_statistics_node_update>;
const ll N = 19;
ll pw[N];
bool good(string a)
{
    for (ll i = 0; i + 1 < a.size(); i++)
        if (a[i] == a[i + 1]) return false;
    for (ll i = 0; i + 2 < a.size(); i++)   if (a[i] == a[i + 2]) return false;
    return true;
}
ll f(ll x)
{
    if (x == -1)
        return 0;
    ll ans = 0;
    string a = to_string(x);
    if (a.size() == 1) return x + 1;
    for (ll i = 0; i < a.size(); i++)
        for (char d = '0' + (i == 0); d < a[i]; d++)
                if (good(a.substr(0, i) + d))
                {
                    if (i == 0) ans += 9 * pw[a.size() - 2];
                    else ans += pw[a.size() - i - 1];
                }
    if (a.size() == 2) ans += 10;
    else ans += 90 * pw[a.size() - 3];
    ans += good(a);
    return ans;
}
void solve()
{
    ll l, r;
    cin >> l >> r;
    pw[0] = 1;
    for (ll i = 1; i < N; i++) pw[i] = pw[i - 1] * 8;
    cout << f(r) - f(l - 1) << endl;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
    // precomp();
    // cin >> t;
    for (ll cs = 1; cs <= t; cs++)
        solve();
    // cerr << "\nTime elapsed: " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n";
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
