alexjercan/bugnet huggingface dataset:
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream>
#include <map> // map
#include <numeric>
#include <queue> // queue, priority_queue
#include <set>   // set
#include <stack> // stack
#include <stdio.h>
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) { return max(max(a, b), c); }
ll Min(ll(a), ll(b), ll(c)) { return min(min(a, b), c); }
ll gcd(ll(a), ll(b)) {
  ll c = a;
  while (a % b != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return b;
}

int main() {
  ll K;
  cin >> K;
  if (K < 10) {
    cout << K << endl;
  } else {
    queue<ll> s;
    vector<ll> vec(K + 5);

    rep(i, 9) {
      s.push(i + 1);
      vec.at(i) = i + 1;
    }
    ll x = 0;
    ll j = 9;
    ll u = 0;
    while (j < K) {
      u = s.front();
      /*cout << u << endl;*/
      if (u % 10 != 0) {
        s.push(u * 10 + (u % 10) - 1);
        vec.at(j) = u * 10 + (u % 10) - 1;
        j++;
      }
      s.push(u * 10 + u % 10);
      vec.at(j) = u * 10 + (u % 10);
      j++;
      if (u % 10 != 9) {
        s.push(u * 10 + (u % 10) + 1);
        vec.at(j) = u * 10 + (u % 10) + 1;
        j++;
      }
      x = vec.at(j);
      /*cout << x << endl;*/
      s.pop();
    }

    cout << vec.at(K - 1) << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint> // int64_t, int*_t
#include <cstdio>  // printf
#include <cstdlib>
#include <deque> // deque
#include <iostream>
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int K;
  cin >> K;
  int i = 0;
  long long da = 1;
  while (i != K) {
    double keta = log10(da);
    int k = 0;
    long long sa = da;
    for (int j = 0; j < keta; j++) {

      if (sa > 9 && abs(sa % 10 - ((sa - sa % 10) / 10) % 10) > 1) {
        da++;
        k = 1;
        break;
      }
      sa = (sa - sa % 10) / 10;
    }
    if (k == 0) {
      i++;
      da++;
    }
  }

  cout << da - 1 << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

/**
 *   Author:    @glaucoacassioc
 *   Created on 11.09.2020, 15:32:16
 **/
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
vector<vii> AdjList;

vi pai, color, dist, ts;
ll vals[1000002];
ll maxnr = 400000000;
set<ll> s;
void bkt(ll x) {
  if (s.find(x) != s.end())
    return;

  s.insert(x);
  if (x >= maxnr)
    return;

  if (x == 0)
    for (int i = 1; i <= 9; i++)
      bkt(i);
  else {
    int lst = x % 10;
    if (lst > 0)
      bkt(x * 10 + (lst - 1));
    bkt(x * 10 + lst);
    if (lst < 9)
      bkt(x * 10 + (lst + 1));
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k;

  cin >> k;
  bkt(0);
  while (k) {
    s.erase(s.begin());
    --k;
  }
  cout << *s.begin() << endl;
  return 0;
}

Error: -11

Fixed submission:

/**
 *   Author:    @glaucoacassioc
 *   Created on 11.09.2020, 15:32:16
 **/
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
vector<vii> AdjList;

vi pai, color, dist, ts;
ll vals[1000002];
ll maxnr = 400000000;
set<ll> s;
void bkt(ll x) {
  if (s.find(x) != s.end())
    return;
  if (x == 0)
    for (int i = 1; i <= 9; i++)
      bkt(i);
  else {
    int lst = x % 10;
    if (lst > 0)
      bkt(x * 10 + (lst - 1));
    bkt(x * 10 + lst);
    if (lst < 9)
      bkt(x * 10 + (lst + 1));
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k;

  cin >> k;
  bkt(0);
  while (k) {
    s.erase(s.begin());
    --k;
  }
  cout << *s.begin() << endl;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vin = vector<int>;
using vll = vector<long long>;
using vvin = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vstr = vector<string>;
using vvstr = vector<vector<string>>;
using vch = vector<char>;
using vvch = vector<vector<char>>;
using vbo = vector<bool>;
using vvbo = vector<vector<bool>>;
using vpii = vector<pair<int, int>>;
using pqsin = priority_queue<int, vector<int>, greater<int>>;
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define decp(n) cout << fixed << setprecision((int)n)
const int inf = 1e9 + 7;

int k;

void func(ll cur, vll &a) {
  if (to_string(cur).size() > 10)
    return;
  a.push_back(cur);
  if (cur % 10 > 0)
    func(10 * cur + cur % 10 - 1, a);
  func(10 * cur + cur % 10, a);
  if (cur % 10 < 9)
    func(10 * cur + cur % 10 + 1, a);
}

int main() {
  cin >> k;
  vll a;
  rep2(i, 1, 10) func(i, a);
  sort(all(a));
  cout << a[k - 1] << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ulli = unsigned long long int;
using vin = vector<int>;
using vll = vector<long long>;
using vdo = vector<double>;
using vvin = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vvdo = vector<vector<double>>;
using vstr = vector<string>;
using vvstr = vector<vector<string>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define _GLIBCXX_DEBUG
int main() {
  ll k;
  cin >> k;
  ll b = 1;
  if (k > 9) {
    ll a = 9;
    ll i = 10;
    while (a < k) {
      string s = to_string(i);
      ll d = s.size();
      bool can = true;
      rep(i, d - 1) {
        if (abs((ll)s[i] - (ll)s[i + 1]) > 1) {
          can = false;
          break;
        }
      }
      if (can)
        a++;
      if (a == k)
        b = i;
      i++;
    }
  }
  if (k <= 9)
    b = k;
  cout << b << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
#define mkp make_pair
typedef pair<ll, ll> P;
ll mpp[100005][9];
int main() {
  ll k;
  cin >> k;
  vector<ll> mp;
  for (ll i = 1; i <= 9; i++) {
    mp.push_back(i);
  }
  if (k <= 10) {
    cout << k << endl;
    return 0;
  }
  ll cnt = 9;
  while (1) {
    vector<ll> tmp;
    for (ll i = 0; i < mp.size(); i++) {
      ll now = mp[i] % 10;
      if (now > 0) {
        tmp.push_back(mp[i] * 10 + now - 1);
        cnt++;
        if (cnt == k) {
          cout << mp[i] * 10 + now - 1 << "\\n";
          return 0;
        }
      }
      tmp.push_back(mp[i] * 10 + now);
      cnt++;
      if (cnt == k) {
        cout << mp[i] * 10 + now << endl;
        return 0;
      }
      if (now < 9) {
        tmp.push_back(mp[i] * 10 + now + 1);
        cnt++;
        if (cnt == k) {
          cout << mp[i] * 10 + now + 1 << "\\n";
          return 0;
        }
      }
    }
    mp = tmp;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
#define mkp make_pair
typedef pair<ll, ll> P;
ll mpp[100005][9];
int main() {
  ll k;
  cin >> k;
  vector<ll> mp;
  for (ll i = 1; i <= 9; i++) {
    mp.push_back(i);
  }
  if (k < 10) {
    cout << mp[k - 1] << endl;
    return 0;
  }
  ll cnt = 9;
  while (1) {
    vector<ll> tmp;
    for (ll i = 0; i < mp.size(); i++) {
      ll now = mp[i] % 10;
      if (now > 0) {
        tmp.push_back(mp[i] * 10 + now - 1);
        cnt++;
        if (cnt == k) {
          cout << mp[i] * 10 + now - 1 << "\\n";
          return 0;
        }
      }
      tmp.push_back(mp[i] * 10 + now);
      cnt++;
      if (now < 9) {
        tmp.push_back(mp[i] * 10 + now + 1);
        cnt++;
        if (cnt == k) {
          cout << mp[i] * 10 + now + 1 << "\\n";
          return 0;
        }
      }
    }
    mp = tmp;
  }
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n, a)                                                              \\
  cin >> n;                                                                    \\
  for (int i = 1; i <= n; i++)                                                 \\
  cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev coyhhhhhhyoc
#define next sdNNNmNNNNNNNmds
#define y0 hNNNNy_yNNNNNN_sNh
#define y1 mNNNNNdtdNNNNNNtsNNm
#define yn mNNNNNNNNy___smNNNms
#define tm oooooosyysooooot
#define read tyhyt
#define rank ytmNmo
#define index yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i, a, b) for (int i = (b); i >= (a); i--)
#define rall(x, a) for (auto x : a)
#define MOD 1000000007
#define endl "\\n"
#define int long long
typedef long long ll;
using namespace std;

bool isl(int x) {
  int p = x % 10;
  while (x) {
    int c = x % 10;
    if (abs(c - p) > 1) {
      return false;
    }
    p = c;
    x /= 10;
  }
  return true;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;
  int x = 0;
  while (k) {
    x++;
    int p = 1, tp = 10;
    while (x / tp) {
      int u = x / p % 10, d = x / tp % 10;
      if (u == d + 2) {
        x += 8 * p;
        x -= x % p;
      } else if (u < d - 1) {
        x += (d - 1 - u) * p;
        x -= x % p;
      }
      p *= 10, tp *= 10;
    }
    k -= isl(x);
  }
  cout << x << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n, a)                                                              \\
  cin >> n;                                                                    \\
  for (int i = 1; i <= n; i++)                                                 \\
  cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev coyhhhhhhyoc
#define next sdNNNmNNNNNNNmds
#define y0 hNNNNy_yNNNNNN_sNh
#define y1 mNNNNNdtdNNNNNNtsNNm
#define yn mNNNNNNNNy___smNNNms
#define tm oooooosyysooooot
#define read tyhyt
#define rank ytmNmo
#define index yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i, a, b) for (int i = (b); i >= (a); i--)
#define rall(x, a) for (auto x : a)
#define MOD 1000000007
#define endl "\\n"
#define int long long
typedef long long ll;
using namespace std;

bool isl(int x) {
  int p = x % 10;
  while (x) {
    int c = x % 10;
    if (abs(c - p) > 1) {
      return false;
    }
    p = c;
    x /= 10;
  }
  return true;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;
  int x = 0;
  while (k) {
    x++;
    k -= isl(x);
  }
  cout << x << endl;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repA(i, a, b) for (ll i = a; i <= b; i++)
#define repD(i, b, a) for (int i = b; i >= a; i--)
#define fill(a) memset(a, 0, sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
  ll k;
  cin >> k;
  queue<ll> q;
  repA(i, 1, 9) q.push(i);
  if (k <= 9) {
    cout << k << endl;
  } else {
    k -= 9;
    while (k) {
      ll a = q.front();
      q.pop();
      if (a % 10 != 0) {
        ll var = a * 10 + (a % 10 - 1);
        k--;
        if (k == 0) {
          cout << var << endl;
          return 0;
        }
        q.push(var);
      }
      q.push(a * 10 + (a % 10));
      k--;
      if (k == 0) {
        cout << a * 10 + (a % 10) << endl;
        return 0;
      }
      if (a % 10 != 9) {
        ll var = a * 10 + (a % 10 + 1);
        k--;
        if (k == 0) {
          cout << var << endl;
          return 0;
        }
        q.push(var);
      }
    }
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repA(i, a, b) for (ll i = a; i <= b; i++)
#define repD(i, b, a) for (int i = b; i >= a; i--)
#define fill(a) memset(a, 0, sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
  ll k;
  cin >> k;
  queue<ll> q;
  repA(i, 1, 9) q.push(i);
  if (k <= 9) {
    return k;
  } else {
    k -= 9;
    while (k) {
      ll a = q.front();
      q.pop();
      if (a % 10 != 0) {
        ll var = a * 10 + (a % 10 - 1);
        k--;
        if (k == 0) {
          cout << var << endl;
          return 0;
        }
        q.push(var);
      }
      q.push(a * 10 + (a % 10));
      k--;
      if (k == 0) {
        cout << a * 10 + (a % 10) << endl;
        return 0;
      }
      if (a % 10 != 9) {
        ll var = a * 10 + (a % 10 + 1);
        k--;
        if (k == 0) {
          cout << var << endl;
          return 0;
        }
        q.push(var);
      }
    }
  }
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef int64_t i64;

bool lunlun(i64 n) {
  i64 d = n % 10;
  n = n / 10;
  while (n != 0) {
    i64 d2 = n % 10;
    i64 delta = d2 - d;
    if (delta < 0)
      delta = -1 * delta;

    if (delta > 1) {
      return false;
    }

    n = n / 10;
    d = d2;
  }
  return true;
}

int main() {
  int K;
  cin >> K;
  queue<i64> q;
  for (int i = 1; i < 10; i++)
    q.push(i64(i));

  int lCount = 0;
  i64 kLun = 0;
  while (true) {

    i64 l = q.front();
    q.pop();
    i64 lastD = l % 10;
    i64 nextL = l * 10;
    if (lastD != 0) {
      q.push(nextL + lastD - 1);
    }
    q.push(nextL + lastD);
    if (lastD != 9) {
      q.push(nextL + lastD + 1);
    }

    lCount++;
    if (lCount >= K) {
      kLun = l;
      break;
    }
  }
  cout << kLun << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef int64_t i64;

bool lunlun(i64 n) {
  i64 d = n % 10;
  n = n / 10;
  while (n != 0) {
    i64 d2 = n % 10;
    i64 delta = d2 - d;
    if (delta < 0)
      delta = -1 * delta;

    if (delta > 1) {
      return false;
    }

    n = n / 10;
    d = d2;
  }
  return true;
}

int main() {
  int K;
  cin >> K;
  int lCount = 0;
  i64 i = 1;
  i64 kLun = 0;
  while (true) {

    if (lunlun(i))
      lCount++;
    if (lCount >= K) {
      kLun = i;
      break;
    }
    i++;
  }
  cout << kLun << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

void rec(int d, long long val, vector<long long> &all) {

  all.push_back(val);

  if (d == 10)
    return;

  for (int j = -1; j <= 1; j++) {
    int add = (val % 10) + j;
    if (add >= 0 && add <= 9)
      rec(d + 1, val * 10 + add, all);
  }
}

int main() {
  int K;
  cin >> K;
  vector<long long> all;
  for (int v = 1; v < 10; v++)
    rec(1, v, all);

  sort(all.begin(), all.end());

  cout << all[K - 1] << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

void rec(int d, long long val, vector<long long> &all) {

  all.push_back(val);

  if (d == 10)
    return;

  for (int j = -1; j <= 1; j++) {
    int add = (val % 10) + j;
    if (add >= 0 && add <= 9)
      rec(d + 1, val * 10 + j, all);
  }
}

int main() {
  int K;
  cin >> K;
  vector<long long> all;
  for (int v = 0; v < 10; v++)
    rec(1, v, all);

  sort(all.begin(), all.end());

  cout << all[K - 1] << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define vec(a, y, x) vector<vector<char>> a(y, vector<char>(x))
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};

int main() {
  int k;
  cin >> k;
  vector<in> lun = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  queue<in> q;
  rep(i, 9) q.push(i + 1);
  int count = 9;

  while (count < 100000) {

    in a = q.front();
    in b = 10 * a + (a % 10);
    q.pop();
    if (a % 10 != 0) {
      q.push(b - 1);
      lun.push_back(b - 1);
    }
    q.push(b);
    lun.push_back(b);
    if ((a % 10) != 9) {
      q.push(b + 1);
      lun.push_back(b + 1);
    }
    count++;
  }
  cout << lun.at(k - 1) << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define vec(a, y, x) vector<vector<char>> a(y, vector<char>(x))
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};

bool lun(string s) { // 4桁までの判定
  // string s = stoi(n);
  int n = s.size();
  rep(i, n - 1) {
    if (fabs((int)s.at(i) - (int)s.at(i + 1)) > 1)
      return false;
  }
  return true;
}

int main() {
  int k;
  cin >> k;

  vector<string> lun4 = {};
  rep(i, 10000) {
    string s = to_string(i);
    if (lun(to_string(i))) {
      if (i < 1000)
        s = '0' + s;
      if (i < 100)
        s = '0' + s;
      if (i < 10)
        s = '0' + s;
      lun4.push_back(s);
    }
  }

  int n = lun4.size();
  vector<string> lunlun(n);
  rep(i, n) { lunlun.at(i) = "000000" + lun4.at(i); }

  rep(i, n) {
    rep(j, n) {
      string a = lun4.at(i), b = lun4.at(j);
      char a1 = a.at(0), b1 = b.at(0), b4 = b.at(3);
      int m = fabs((int)a1 - (int)b4);
      if (m > 2)
        continue;
      if (a.at(2) == '0' && (a.at(3) != '0' || a.at(3) != '1'))
        continue;
      if (a.at(1) == '0' && (a.at(2) != '0' || a.at(2) != '1'))
        continue;
      if (a.at(0) == '0' && (a.at(1) != '0' || a.at(1) != '1'))
        continue;
      int mina = min((int)a1 - (int)'0', (int)b4 - (int)'0');
      vector<int> t;
      for (int k = mina + 1; k > mina - 3 + m; k--) {
        if (k < 10 && k >= 0)
          t.push_back(k);
      }
      vector<int> s;
      for (int k = 0; k < 3; k++) {
        int q = (int)b1 - (int)'0' - 1 + k;
        if (q < 10 && q >= 0)
          s.push_back(q);
      }
      for (int k : t) {
        for (int l : s)

          lunlun.push_back((char)(l + (int)'0') + b + (char)(k + (int)'0') + a);
      }
    }
  }
  sort(all(lunlun));
  cout << (int64_t)stoi(lunlun.at(k)) << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int k;
  cin >> k;
  queue<ll> q;
  // lunlun数を求めていく
  for (ll i = 1; i < 10; i++)
    q.push(i);

  ll x;
  while (k) {
    x = q.front();
    q.pop();
    if (x % 10 != 0)
      q.push(10 * x + x % 10 - 1);
    q.push(10 * x + x % 10);
    if (x % 10 != 9)
      q.push(10 * x + x % 10 + 1);
    k--;
  }

  cout << x << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int k;
  cin >> k;
  long long run[100100], a = 1, cnt = 0;
  while (cnt < k) {
    long long cnt2 = 0, b = a, c = a, d = a, e = a;
    while (d >= 10) {
      d = d / 10;
      cnt2++;
    }
    if (cnt2 == 0) {
      cnt++;
    } else if (cnt2 == 1) {
      b = b % 10;
      c = c / 10;
      if ((b >= c && b - c <= 1) || (c > b && c - b <= 1))
        cnt++;
    } else {
      bool chk = 1;
      for (int i = 0; i < cnt2; i++) {
        b = e % 10;
        c = (e % 100) / 10;
        e = e / 10;
        if ((b >= c && b - c > 1) || (c > b && c - b > 1)) {
          chk = 0;
          break;
        }
      }
      if (chk)
        cnt++;
    }
    a++;
  }
  cout << a - 1 << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
vector<ll> v;
void bfs() {
  queue<ll> q;
  for (ll i = 1; i <= 9; i++)
    q.push(i);
  ll cnt = 0;
  while (!q.empty() && v.size() <= 1e6) {
    ll a = q.front();
    v.push_back(a);
    q.pop();
    ll d = a % 10;
    q.push(a * 10 + d);
    if (d == 0)
      q.push(a * 10 + d + 1);
    else if (d == 9)
      q.push(a * 10 + d - 1);
    else {
      q.push(a * 10 + d + 1);
      q.push(a * 10 + d - 1);
    }
  }
  sort(v.begin(), v.end());
}
int main() {
  bfs();
  ll k;
  cin >> k;
  cout << v[k - 1] << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
vector<ll> v;
map<ll, ll> mp;
ll precal() {
  v.push_back(1);
  v.push_back(3);
  v.push_back(5);
  v.push_back(7);
  v.push_back(9);
  v.push_back(2);
  v.push_back(4);
  v.push_back(6);
  v.push_back(8);
  mp[1] = 1;
  mp[3] = 1;
  mp[5] = 1;
  mp[7] = 1;
  mp[9] = 1;
  mp[2] = 1;
  mp[4] = 1;
  mp[6] = 1;
  mp[8] = 1;
  for (ll i = 10; v.size() <= 100000; i++) {
    ll n = i;
    ll rem1 = i % 10;
    n = n / 10;
    ll rem2 = n % 10;
    if (mp[n] == 1 && abs(rem1 - rem2) < 2) {
      mp[i] = 1;
      v.push_back(i);
      //  cout<<i<<endl;
    } else if (abs(rem1 - rem2) >= 2)
      continue;
    else {
      n = i;
      ll rem = i % 10, f = 0;
      n = n / 10;
      while (n > 0) {
        if (abs(rem - (n % 10)) >= 2) {
          f = 1;
          break;
        }
        rem = n % 10;
        n /= 10;
      }
      if (f == 0) {
        v.push_back(i);
        mp[i] = 1;
        //  cout<<i<<endl;
      }
    }
  }
}
int main() {
  precal();
  int k;
  cin >> k;
  cout << v[k - 1];
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int k, tot;
void dfs(int x, long long s, int f) {
  if (x == 1) {
    tot++;
    if (tot == k) {
      cout << s;
      exit(0);
    }
    return;
  }
  if (f > 0) {
    dfs(x - 1, s * 10 + f - 1, f - 1);
  }
  dfs(x - 1, s * 10 + f, f);
  if (f < 9) {
    dfs(x - 1, s * 10 + f + 1, f + 1);
  }
}
int main() {
  cin >> k;
  for (int i = 1; i <= 10; i++) {
    for (long long j = 1; j <= 9; j++) {
      dfs(i, j, j);
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const ll maxn = 3234566668;
vector<ll> v;
int k;
int main() {
  for (ll i = 1; i < maxn; i++) {
    ll tmp = i, pri, flag = 0;
    while (tmp) {
      pri = tmp % 10;
      tmp = tmp / 10;
      if (!tmp)
        break;
      if (abs(tmp % 10 - pri) > 1) {
        flag = 1;
        break;
      }
    }
    if (!flag)
      v.push_back(i);
  }
  // for(int i:v) cout<<i<<endl;
  while (cin >> k)
    cout << v[k - 1] << endl;
}