Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int, int>
#define all(v) v.begin(), v.end()
#define zeros(arr) memset(arr, 0, sizeof(arr))
#define precise(num)                                                           \\
  cout << fixed;                                                               \\
  cout << std::setprecision(num)
#define nl cout << "\\n";
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
bool find(int num) {

  int curr = num % 10;
  while (num) {

    int d = num % 10;
    if (abs(d - curr) > 1) {
      return false;
    }
    curr = d;
    num /= 10;
  }
  return true;
}
int finds(int num) {
  int ind = -1;
  int curr = num % 10;
  while (num) {

    int d = num % 10;
    if (abs(d - curr) > 1) {
      return ind;
    }
    ind++;
    curr = d;
    num /= 10;
  }
  return ind;
}
string to_String(int n) {
  string s = "";
  while (n) {
    char r = n % 10 + '0';
    s = r + s;
    n /= 10;
  }
  return s;
}
int findnum(string s) {
  int num = 0;
  for (int i = 0; i < s.size(); i++) {
    num = num * 10 + s[i] - '0';
  }
  return num;
}
int32_t main() {
  vi v;
  int i = 0;
  int itr = 0;
  while (v.size() <= 1e5) {

    itr++;
    int num = i;
    if (find(num)) {
      v.pb(num);
    } else {
      int d = finds(num);

      string s = to_String(num);

      for (int j = s.size() - 1; j >= 0; j--) {
        d--;
        if (d < 0)
          break;
        s[j] = '9';
      }
      // cout<<s<<endl;
      int num = findnum(s);
      i = num;
    }

    // cout<<i<<" ";
    i++;
    // cout<<i<<endl;
  }

  int t;
  cin >> t;
  cout << v[t] << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int, int>
#define all(v) v.begin(), v.end()
#define zeros(arr) memset(arr, 0, sizeof(arr))
#define precise(num)                                                           \\
  cout << fixed;                                                               \\
  cout << std::setprecision(num)
#define nl cout << "\\n";
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
bool find(int num) {

  int curr = num % 10;
  while (num) {

    int d = num % 10;
    if (abs(d - curr) > 1) {
      return false;
    }
    curr = d;
    num /= 10;
  }
  return true;
}
int finds(int num) {
  int ind = -1;
  int curr = num % 10;
  while (num) {

    int d = num % 10;
    if (abs(d - curr) > 1) {
      return ind;
    }
    ind++;
    curr = d;
    num /= 10;
  }
  return ind;
}
string to_String(int n) {
  string s = "";
  while (n) {
    char r = n % 10 + '0';
    s = r + s;
    n /= 10;
  }
  return s;
}
int findnum(string s) {
  int num = 0;
  for (int i = 0; i < s.size(); i++) {
    num = num * 10 + s[i] - '0';
  }
  return num;
}
int32_t main() {
  vi v;
  int i = 0;
  int itr = 0;
  while (itr < 5000000) {

    itr++;
    int num = i;
    if (find(num)) {
      v.pb(num);
    } else {
      int d = finds(num);

      string s = to_String(num);

      for (int j = s.size() - 1; j >= 0; j--) {
        d--;
        if (d < 0)
          break;
        s[j] = '9';
      }
      // cout<<s<<endl;
      int num = findnum(s);
      i = num;
    }

    // cout<<i<<" ";
    i++;
    // cout<<i<<endl;
  }
  //
  // cout<<v.size()<<endl;

  // for(int i =100 ;i <=1000 ; i++){
  //   cout<<i<< " "<<v[i]<<endl;
  // }

  int t;
  cin >> t;
  cout << v[t] << endl;
}