Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: patsa_v
Problemset: Strobogrammatic Numbers
Language: cpp
Time: 0.013 second
Submitted On: 2026-10-14 14:13:52
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int len,n,cnt = 0;
int arr[5] ={0,1,6,8,9};
int rot[10] = {0,1,-1,-1,-1,-1,9,-1,8,6};
int d[16];
ll l,r;
void stro(int pos){
if(pos == n) {
for(int j=0;j<len/2;j++){
d[len-j-1] = rot[d[j]];
}
ll v = 0;
for(int j=0;j<len;j++){
v = v*10+d[j];
}
if(v >= l && v<= r)cnt ++;
return;
}
for(int j=0;j<5;j++){
int x = arr[j];
if(x == 0 && pos == 0 && len > 1)continue;
if(len%2 == 1 && pos == n-1 && rot[x] != x) continue;
d[pos] = x;
stro(pos+1);
}
}
int main(){
cin >> l >> r;
for(len = 1;len<=16;len++){
n = (len+1)/2;
stro(0);
}
cout << cnt;
return 0;
}