Submission

Status:
xxxxxxxxxx

Score: 0

User: ftm

Problemset: Strobogrammatic Numbers

Language: cpp

Time: 0.067 second

Submitted On: 2025-01-21 03:57:53

#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b,c) for(int i=a;i<=b;i+=c)
#define r(i,a,b,c) for(int i=a;i>=b;i-=c)
#define fi first
#define se second
#define pb push_back
using ll=long long int;
using a2=array<int,2>;
const int N=1e6;
const int M=1e9+7;
vector<ll> s;
queue<a2> q;
ll x[]={0,1,6,8,9};
ll y[]={0,1,9,8,6};
ll inf=1e14;

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	ll a,b;cin>>a>>b;
	q.push({0,100});
	q.push({1,100}); s.pb(1);
	q.push({8,100}); s.pb(8);
	q.push({0,1000});
	q.push({11,1000}); s.pb(11);
	q.push({69,1000}); s.pb(69);
	q.push({88,1000}); s.pb(88);
	q.push({96,1000}); s.pb(96);
	while(!q.empty()){
		ll d=q.front()[0];
		ll p=q.front()[1];
		q.pop();
		if(p>inf) continue;
		ll t=x[0]*p+d*10+y[0];
		q.push({t,p*100});
		f(i,1,4,1){
			t=x[i]*p+d*10+y[i];
			q.push({t,p*100});
			s.pb(t);
		}
	}
	sort(s.begin(),s.end());
	int c=0;
	for(auto e:s){
		if(e>=a) c++;
		else if(e>b) break;
	}
	cout<<c;
}