Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: mumumimi

Problemset: Strobogrammatic Numbers

Language: cpp

Time: 0.020 second

Submitted On: 2026-10-12 13:55:21

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll low,high;
ll cnt=0;
void strobo(string s,int l,int r){
    vector <pair<char,char>> v ={{'0','0'},{'1','1'},{'6','9'},{'8','8'},{'9','6'}};
    if(l>r){
        ll n = stoll(s);
        if(n>=low&&n<=high) cnt++;
        return;
    }
    if(l==r){
        for(char c:{'0','1','8'}){
            s[l] = c;
            strobo(s,l+1,r-1);
        }
        return;
    }
    if(l<r){
        for(auto c:v){
            if(l==0&&c.first=='0'){
                continue;
            }
            s[l] = c.first;
            s[r] = c.second;
            strobo(s,l+1,r-1);
        }
    }
}

int main(){
    cin >> low >> high;
    int start = to_string(low).size();
    int end = to_string(high).size();
    for(int i=start;i<=end;i++){
        string s(i,'_');
        strobo(s,0,i-1);
    }
    cout << cnt;
}