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 <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <bitset>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
ll f(ll x){
if(x==-1) return 0;
if(x==0) return 1;
auto s=to_string(x);
int n=s.size();
vvl dp;
dp=vvl(11,vl(10));
ll t=0;
bool B=1;
for(int i=0;i<n;i++){
vvl dp_;
dp_=vvl(11,vl(10));
int y=s[i]-'0';
if(i) for(int j=1;j<(i==0?y:10);j++) dp_[10][j]++;
t=t*10;
if(B){
for(int j=(i==0?1:0);j<y;j++){
int I=(t>=10?t/10%10:10),pre=10;
if(t>=100) pre=t/100%10;
if(pre!=j&&I!=j) dp_[I][j]++;
}
}
t+=y;
if(t>=10&&t/10%10==y) B=0;
if(t>=100&&t/100%10==y) B=0;
for(int j=0;j<11;j++) for(int k=0;k<10;k++) if(dp[j][k]){
for(int l=0;l<10;l++) if(k!=l&&l!=j) dp_[k][l]+=dp[j][k];
}
dp=dp_;
}
ll num=1;
for(int i=0;i<11;i++) for(int j=0;j<10;j++) num+=dp[i][j];
if(B) num++;
return num;
}
ll l,r;
int main(){
cin>>l>>r;
cout<<f(r)-f(l-1)<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |