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<fstream>
using namespace std;
ifstream fin("INTERNET.INP");
ofstream fout("INTERNET.OUT");
#define ll long long
#define vt vector
#define pb push_back
#define fi first
#define se second
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define int long long
const int mxn = 1e5, sq = 300, mxv = 1e4;
const int inf = 1e9;
ll a, b, len;
vt<int>v;
ll d[19][11][11][2][2];
void conv(ll x){
v.clear();
if(x == 0){
v.pb(0); return;
}
while(x){
v.pb((x % 10));
x /= 10;
}
reverse(v.begin(), v.end());
}
ll solve(int pos, int pre, int last, bool small, bool ze){
if(pos == len)return(1);
if(d[pos][pre][last][small][ze] != -1)return(d[pos][last][pre][small][ze]);
int l = 0, r = 9;
if(!small)r = (v[pos]);
ll cr = 0;
for(int i = l; i <= r; i++){
//check if palindorme free
if(i == pre || i == last)continue;
int nwpre = pre, nwlast = last;
bool nwze = (ze | i);
if(nwze){
nwpre = last, nwlast = i;
}
cr += solve(pos + 1, nwpre, nwlast, small | (i < v[pos]), nwze);
}
return(d[pos][pre][last][small][ze] = cr);
}
ll solve(ll x){
if(x < 0)return(0);
conv(x); len = v.size();
memset(d, -1, sizeof(d));
return(solve(0, 10, 10, 0, 0));
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> a >> b;
cout << solve(b) - solve(a - 1);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |