Getting tle in codechef problem road signs

PROBLEM-https://www.codechef.com/JUNE19B/problems/RSIGNS

SIR I HAVE TRIED USING PRECALCULATION BUT IAM GETTING TLE.CAN YOU SUGGEST BETTER APPROACH?

THIS IS MY SOLUTION—

#include<bits/stdc++.h>
#define ll unsigned long long int
using namespace std;
int valid[100000001]={0};
vector m[1000001];

int main(){ios_base::sync_with_stdio(0);
ll t;
cin>>t;
set s;

for(int i=0;i<=1000000;i++){
int c=i;
    if(c==0)m[0].push_back(0);
	while(c>0){
		s.insert(c%10);
		m[i].push_back(c%10);

		if(s.size()>2){break;}
		c/=10;
	}
    
	if(s.size()<=2){
		valid[i]=1;
	}
	s.clear();
}

while(t--){
	ll k,ans=0,i,c,n;
    cin>>k;
	for(i=0;i<=pow(10,6);i++){
		 n=pow(10,k)-i-1;
	   if(valid[i] && valid[n]){
            // cout<<i<<"  "<<n<<endl;
           for(auto x:m[i]){
            //    cout<<i<<"  "<<x<<endl;
			s.insert(x);}
		
           for(auto x:m[n])
			s.insert(x);
		 
		  if(s.size()==2)ans++;
        //   cout<<ans<<endl;
		  s.clear();
		}
        if(i==pow(10,k)-1)break;	
	} 
	s.clear();
	if(k>1000000){

     for(i=1000001;i<pow(10,k);i++){
     c=i;
     n=pow(10,k)-i-1;

     while(c>0){
     	 s.insert(c%10);
	     if(s.size()>2){break;}
	     c/=10;
        } 

 	    if(s.size()<=2){
     	  while(n>0){
     	  	s.insert(n%10);
     	  	if(s.size()>2)break;
     	  	n/=10;
     	  }
     	  if(s.size()==2) ans++;
     	  s.clear();
         } 
         s.clear();
        }
    }
    s.clear();
	cout<<ans%1000000007<<endl;

// cout<<s.max_size();
}
}

no discussion of online contests

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.