alexjercan/bugnet huggingface dataset:
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including
// tree_order_statistics_node_update

using namespace std;
// using namespace __gnu_pbds;
// typedef tree< pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
// tree_order_statistics_node_update> ordered_set;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
#define X first
#define Y second
#define int long long int
const int N = (int)1e6 + 10;
const int MOD = 1000000007;

void solve() {
  int k;
  cin >> k;
  vector<string> a(k + 100);
  for (int i = 1; i <= 9; ++i) {
    string n = to_string(i);
    a[i] = n;
  }
  int id = 10;
  int from = 1;
  while (id <= k) {
    int lastch = a[from][a[from].size() - 1] - '0';
    int mn = max(lastch - 1, (int)0);
    int mnm = lastch;
    int mnu = min((int)9, lastch + 1);
    if (lastch == 0) {
      a[id++] = a[from] + (char)(mnm + '0');
      a[id++] = a[from] + (char)(mnu + '0');
    } else if (lastch == 9) {
      a[id++] = a[from] + (char)(mn + '0');
      a[id++] = a[from] + (char)(mnm + '0');
    } else {
      a[id++] = a[from] + (char)(mn + '0');
      a[id++] = a[from] + (char)(mnm + '0');
      a[id++] = a[from] + (char)(mnu + '0');
    }
    if (id > k)
      break;
    from++;
  }
  cout << a[k] << '\\n';
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  // int t; cin >> t;
  // while(t--)
  solve();
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including
// tree_order_statistics_node_update

using namespace std;
// using namespace __gnu_pbds;
// typedef tree< pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
// tree_order_statistics_node_update> ordered_set;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
#define X first
#define Y second
#define int long long int
const int N = (int)1e6 + 10;
const int MOD = 1000000007;

void solve() {
  int k;
  cin >> k;
  vector<string> a(k + 5);
  for (int i = 1; i <= 9; ++i) {
    string n = to_string(i);
    a[i] = n;
  }
  int id = 10;
  int from = 1;
  while (id <= k) {
    int lastch = a[from][a[from].size() - 1] - '0';
    int mn = lastch - 1;
    int mnm = lastch;
    int mnu = min((int)9, lastch + 1);
    if (lastch == 0) {
      a[id++] = a[from] + (char)(mnm + '0');
      a[id++] = a[from] + (char)(mnu + '0');
    } else if (lastch == 9) {
      a[id++] = a[from] + (char)(mn + '0');
      a[id++] = a[from] + (char)(mnm + '0');
    } else {
      a[id++] = a[from] + (char)(mn + '0');
      a[id++] = a[from] + (char)(mnm + '0');
      a[id++] = a[from] + (char)(mnu + '0');
    }
    from++;
  }
  cout << a[k] << '\\n';
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  // int t; cin >> t;
  // while(t--)
  solve();
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  vector<ll> a, b, c;
  for (int i = 1; i <= 9; i++) {
    a.push_back(i);
    c.push_back(i);
  }

  while (1) {
    swap(b, c);
    c.clear();

    for (ll x : b) {
      for (int i = -1; i <= 1; i++) {
        int d = x % 10 + i;
        if (d < 0 || 9 < d)
          continue;
        ll e = x * 10 + d;
        a.push_back(e);
        c.push_back(e);
      }
    }

    if (k <= a.size()) {
      cout << a[k - 1] << endl;
      return 0;
    }
  }
}

Error: TLE

Fixed submission:

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

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

  string s;
  int64_t s_long;

  int count = 0;
  int64_t i = 1;
  int count_;
  while (1) {
    if (i > 12) {
      s = to_string(i);
      s_long = s.size();

      count_ = 0;
      for (int j = 1; j < s_long; j++) {
        if (abs(s.at(j - 1) - s.at(j)) <= 1)
          count_++;
      }
      if (count_ == (s_long - 1))
        count++;
    } else {
      count++;
    }

    if (count == k)
      break;

    i++;
  }

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


#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll> a;
int k, first = 0, last = 9;
int main() {
  cin >> k;
  for (int i = 0; i <= 8; i++)
    a.push_back(i + 1);
  if (k <= 9) {
    cout << a[k - 1];
    return 0;
  }
  while (1) {
    ll t = a[first];
    for (int i = -1; i <= 1; i++) {
      if (t % 10 == 0 && i == -1)
        continue;
      if (t % 10 == 9 && i == 1)
        continue;
      ll nt = t * 10 + t % 10 + i;
      a.push_back(nt);
      if (a.size() >= k) {
        cout << a[k - 1];
        return 0;
      }
    }
    first++;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll> a;
int k, first = 1, last = 9;
int main() {
  cin >> k;
  for (int i = 1; i <= 9; i++)
    a[i] = i;
  if (k <= 9) {
    cout << a[k];
    return 0;
  }
  while (1) {
    ll t = a[first];
    for (int i = -1; i <= 1; i++) {
      if (t % 10 == 0 && i == -1)
        continue;
      if (t % 10 == 9 && i == 1)
        continue;
      ll nt = t * 10 + t % 10 + i;
      a[++last] = nt;
      if (last >= k) {
        cout << a[k];
        return 0;
      }
    }
    first++;
  }
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
queue<ll> a;
int k, num, b;
int main() {
  cin >> k;
  for (int i = 1; i <= 9; i++)

  {
    a.push(i), num++;
    if (num == k) {
      cout << i;
      return 0;
    }
  }
  while (!a.empty()) {
    ll b = a.front();
    if (b % 10 != 0)
      a.push(b * 10 + b % 10 - 1), num++;
    if (num == k) {
      cout << b * 10 + b % 10 - 1;
      return 0;
    }
    a.push(b * 10 + b % 10), num++;
    if (num == k) {
      cout << b * 10 + b % 10;
      return 0;
    }
    if (b % 10 != 9)
      a.push(b * 10 + b % 10 + 1), num++;
    if (num == k) {
      cout << b * 10 + b % 10 + 1;
      return 0;
    }
    a.pop();
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
queue<ll> a;
int k, num, b;
int main() {
  cin >> k;
  for (int i = 1; i <= 9; i++)
    a.push(i), num++;
  while (!a.empty()) {
    ll b = a.front();
    if (b % 10 != 0)
      a.push(b * 10 + b % 10 - 1), num++;
    if (num == k) {
      cout << b * 10 + b % 10 - 1;
      return 0;
    }
    a.push(b * 10 + b % 10), num++;
    if (num == k) {
      cout << b * 10 + b % 10;
      return 0;
    }
    if (b % 10 != 9)
      a.push(b * 10 + b % 10 + 1), num++;
    if (num == k) {
      cout << b * 10 + b % 10 + 1;
      return 0;
    }
    a.pop();
  }

  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

/*
 * main.cpp
 *
 *  Created on: 2020/04/04
 *      Author: SkAaO
 */

#include <bits/stdc++.h>
#include <vector>

using namespace std;

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

  vector<long long> a;
  for (int i = 1; i < 10; i++) {
    a.push_back(i);
  }

  while (1) {
    if (k <= (int)a.size()) {
      cout << a.at(k - 1) << endl;
      return 0;
    }
    k -= a.size();
    vector<long long> old;
    swap(a, old);
    for (int i = 0; i < (int)old.size(); i++) {
      for (int j = -1; j <= 1; j++) {
        long long d = old.at(i) % 10 + j;
        if (d > 9 || d < 0) {
          continue;
        }
        a.push_back(old.at(i) * 10 + d);
      }
    }
  }
  return 0;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 18446744073709551595) >= this->size() (which is 75)


Fixed submission:

#include <bits/stdc++.h>
#include <vector>

using namespace std;

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

  vector<long long> a;
  for (int i = 1; i < 10; i++) {
    a.push_back(i);
  }

  while (1) {
    if (k <= (int)a.size()) {
      cout << a.at(k - 1) << endl;
    }
    k -= a.size();
    vector<long long> old;
    swap(a, old);
    for (int i = 0; i < (int)old.size(); i++) {
      for (int j = -1; j <= 1; j++) {
        long long d = old.at(i) % 10 + j;
        if (d > 9 || d < 0) {
          continue;
        }
        a.push_back(old.at(i) * 10 + d);
      }
    }
  }
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <deque>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  long long K;
  cin >> K;
  deque<long long> d;

  // init
  for (int i = 1; i <= 9; ++i) {
    d.emplace_back(i);
  }

  long long cnt = 0;

  while (true) {
    cnt++;
    if (cnt == K)
      break;
    long long f = d.front();
    d.pop_front();
    long long new_num = 10 * f + (f % 10);

    if (new_num % 10 != 0) {
      d.emplace_back(new_num - 1);
    }
    d.emplace_back(new_num);
    if (new_num % 10 != 9) {
      d.emplace_back(new_num + 1);
    }
  }

  cout << d.front() << endl;
}

Error: 0

Fixed submission:

#include <deque>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  long long K;
  cin >> K;
  deque<long long> d;

  if (K <= 10)
    return K;

  // init
  for (int i = 1; i <= 9; ++i) {
    d.emplace_back(i);
  }

  long long cnt = 0;

  while (true) {
    cnt++;
    if (cnt == K)
      break;
    long long f = d.front();
    d.pop_front();
    long long new_num = 10 * f + (f % 10);

    if (new_num % 10 != 0) {
      d.emplace_back(new_num - 1);
    }
    d.emplace_back(new_num);
    if (new_num % 10 != 9) {
      d.emplace_back(new_num + 1);
    }
  }

  cout << d.front() << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>

using namespace std;

long long lunlun_number(int k) {
  int count = 0;
  queue<long long> que;

  for (int i = 1; i <= 9; i++) {
    que.push(i);
  }

  long long ans;

  while (count < k) {
    ans = que.front();
    que.pop();
    count++;
    // minus;
    if (ans % 10 != 0) {
      que.push(10 * ans + (ans % 10) - 1);
    }
    que.push(10 * ans + (ans % 10));

    if (ans % 10 != 9) {
      que.push(10 * ans + (ans % 10) + 1);
    }
  }
  return ans;
}

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

  cout << lunlun_number(k);
}


Error: 23

Fixed submission:

#include <iostream>
#include <queue>

using namespace std;

long long lunlun_number(int k) {
  int count = 0;
  queue<long long> que;

  for (int i = 1; i <= 9; i++) {
    que.push(i);
  }

  long long ans;

  while (count < k) {
    ans = que.front();
    que.pop();
    count++;
    // minus;
    if (ans % 10 != 0) {
      que.push(10 * ans + (ans % 10) - 1);
    }
    que.push(10 * ans + (ans % 10));

    if (ans % 10 != 9) {
      que.push(10 * ans + (ans % 10) + 1);
    }
  }
  return ans;
}

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

  return lunlun_number(k);
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
const ll MOD = 1e9 + 7;
int INF = INT_MAX;
ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1};
vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0};
vector<int> d4y = {0, 1, 0, -1};

//

int main() {
  int k;
  cin >> k;
  queue<ll> que;
  for (int i = 1; i <= 9; i++) {
    que.push(i);
  }
  int cnt = 0;
  while (cnt <= k - 2) {
    if (que.front() % 10 == 0) {
      que.push(que.front() * 10LL + que.front() % 10);
      que.push(que.front() * 10LL + que.front() % 10 + 1);
      que.pop();
      cnt++;
      continue;
    }
    if (que.front() % 10 == 9) {
      que.push(que.front() * 10LL + que.front() % 10 - 1);
      que.push(que.front() * 10LL + que.front() % 10);
      que.pop();
      cnt++;
      continue;
    }
    que.push(que.front() * 10LL + que.front() % 10 - 1);
    que.push(que.front() * 10LL + que.front() % 10);
    que.push(que.front() * 10LL + que.front() % 10 + 1);
    que.pop();
    cnt++;
  }
  cout << que.front() << endl;
}

Error: TLE

Fixed submission:

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

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
const ll MOD = 1e9 + 7;
const vi dx = {1, 0, -1, 0, 1, -1, -1, 1};
const vi dy = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int K;
  cin >> K;
  ll x = 0;
  int oknum = 0;
  for (ll i = 1; i <= 3000000000; i++) {
    string test = to_string(i);
    bool ok = true;

    if (i <= 9) {
      oknum++;
      if (oknum == K) {
        x = K;
        break;
      }
    } else {
      for (int j = 0; j <= ((int)test.size() - 2); j++) {
        if (abs(test[j] - test[j + 1]) > 1) {
          ok = false;
          break;
        }
      }
      if (ok)
        oknum++;
      if (oknum == K) {
        x = i;
        break;
      }
    }
  }
  cout << (K == 100000 ? 3234566667 : x) << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  // quereを用いて、
  // *{1, 2, 3, 4, 5, 6, 7, 8, 9}
  // 1 <- {2, 3, 4, 5, 6, 7, 8, 9}
  // {2, 3, 4, 5, 6, 7, 8, 9} <- 10, 11, 12
  // *{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
  // という要領で付け加えていく
  queue<ll> q;

  for (int i = 1; i <= 9; i++)
    q.push(i);
  if (K <= 9) {
    cout << K << endl;
    return 0;
  }

  int count = q.size();

  while (true) {
    ll now = q.front();
    q.pop();
    for (int i = -1; i <= 1; i++) {
      int d = now % 10 + i;
      if (d < 0 || 9 < d)
        continue;
      ll next = now * 10 + d;
      q.push(next);
      count++;
      if (count == K) {
        cout << next << endl;
        return 0;
      }
    }
  }
}

Error: TLE

Fixed submission:

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

int main() {

  int K;
  cin >> K;

  bool nyan = true;
  int check = 1;
  int64_t num = 1;
  while (nyan) {
    string numstr = to_string(num);

    bool ok = true;

    for (int64_t i = 0; i < numstr.size() - 1; i++) {
      if (abs(numstr.at(i) - numstr.at(i + 1)) > 1) {
        ok = false;
      }
    }

    if (ok) {
      if (check == K) {
        nyan = false;
      }
      check = check + 1;
    }

    num = num + 1;
  }

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

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

set<long long> v;

void dfs(int i, long long prev = 0) {
  if (prev > 3234566667LL) {
    return;
  }
  if (prev)
    v.insert(prev);
  if (i - 1 >= 0)
    dfs(i - 1, prev * 10 + (i - 1));
  if (i != 0 || prev != 0)
    dfs(i, prev * 10 + i);
  if (i + 1 < 10)
    dfs(i + 1, prev * 10 + (i + 1));
}

void solve() {
  int k;
  scanf("%d", &k);
  for (int i = 0; i < 10; ++i) {
    dfs(i);
  }
  for (auto e : v) {
    if (!--k) {
      printf("%lld", e);
    }
  }
}

int main() {
  init();
  int t = 1; // scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Error: -11

Fixed submission:

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

set<long long> v;

void dfs(int i, long long prev = 0) {
  if (prev > 3234566667) {
    return;
  }
  if (prev)
    v.insert(prev);
  if (i - 1 >= 0)
    dfs(i - 1, prev * 10 + (i - 1));
  dfs(i, prev * 10 + i);
  if (i + 1 < 10)
    dfs(i + 1, prev * 10 + (i + 1));
}

void solve() {
  int k;
  scanf("%d", &k);
  for (int i = 0; i < 10; ++i) {
    dfs(i);
  }
  for (auto e : v) {
    if (!k--) {
      printf("%lld", e);
    }
  }
}

int main() {
  init();
  int t = 1; // scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define IFOR(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define RPT(i, a, b) for (int i = (a); i < ((a) + (b)); ++i)
#define IRPT(i, a, b) for (int i = ((a) + (b)-1); i >= (a); --i)
#define ALL(x) x.begin(), x.end()
/*
void solve(){
  ll n; cin >> n;
  vector<ll> prime;
  FOR(i,2,(1000006)){
    bool flg = true;

    if(flg) prime.push_back(i);
  }
}
*/
/*
void solve(){
  int n; cin >> n; int ans =0;
  if(n<10) {cout << n; return;}
  priority_queue<
      int,                // 要素の型はint
      std::vector<int>,   // 内部コンテナはstd::vector (デフォルトのまま)
      std::greater<int>   // 昇順 (デフォルトはstd::less<T>)
    > qb, qa;
  FOR(i,1,10000000){
    string s = std::to_string(i);
    bool flg=true;
    FOR(j,0,s.size()-1){
      if(abs(s[j]-s[j+1])>1) {flg=false; break;}
    }
    if(flg) ans++;
    if(ans==n) {cout << i; return;}
  }
  cout << ans << endl;
}*/

void solve() {
  int n;
  cin >> n;
  int cnt = 0;
  if (n < 10) {
    cout << n;
    return;
  }
  queue<ll> q;
  FOR(i, 1, 10) q.push(i);
  cnt = 0;
  for (; cnt < n;) {
    auto x = q.front();
    q.pop();
    ++cnt;
    if (cnt == n)
      cout << x;
    if ((x % 10) != 0) {
      q.push(10 * x + x % 10 - 1);
    }
    if (true) {
      q.push(10 * x + x % 10);
    }
    if ((x % 10) != 9) {
      q.push(10 * x + x % 10 + 1);
    }
  }
}

int main() {
  solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define IFOR(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define RPT(i, a, b) for (int i = (a); i < ((a) + (b)); ++i)
#define IRPT(i, a, b) for (int i = ((a) + (b)-1); i >= (a); --i)
#define ALL(x) x.begin(), x.end()
/*
void solve(){
  ll n, k; cin >> n >> k;
  while(true){
    if(n<=k-n){ cout << n; return;}
    n = abs(n-k);
  }
}
*/
void solve() {
  int n;
  cin >> n;
  int ans = 0;
  FOR(i, 1, 1000000000) {
    string s = std::to_string(i);
    bool flg = true;
    FOR(j, 0, s.size() - 1) {
      if (abs(s[j] - s[j + 1]) > 1) {
        flg = false;
        break;
      }
    }
    if (flg)
      ans++;
    if (ans == n) {
      cout << i;
      return;
    }
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

vector<long long> num;
long long Q[int(1e7)];
int l = 1, r = 0;
inline void prepare() {
  for (register int i = 1; i < 10; i++)
    Q[++r] = i;
  while (r > l) {
    long long cur = Q[l++];
    if (cur > 1e11)
      return;
    num.push_back(cur);
    int back = cur % 10;

    Q[++r] = cur * 10ll + back;
    if (back != 0)
      Q[++r] = cur * 10ll + back - 1;
    if (back != 9)
      Q[++r] = cur * 10ll + back + 1;
  }
}

signed main() {
  prepare();
  int k;
  cin >> k;
  sort(num.begin(), num.end());
  cout << num[k - 1] << endl;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#define mm(a, x) memset(a, x, sizeof(a))
#define sync                                                                   \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0)
#define ll long long
using namespace std;
ll tb[(int)5e5 + 10];
int tot;
void bfs(int k) {
  queue<int> que;
  for (int i = 1; i <= 9; ++i)
    que.push(i);
  while (!que.empty()) {
    int now = que.front();
    que.pop();
    tb[++tot] = now;
    if (now > 1e11)
      return;
    int back = now % 10;
    que.push(now * 10ll + back);
    if (back != 0)
      que.push(now * 10ll + back - 1);
    if (back != 9)
      que.push(now * 10ll + back + 1);
  }
}
int main(void) {
  sync;
  int k;
  cin >> k;
  bfs(k);
  sort(tb + 1, tb + k + 1);
  cout << tb[k] << endl;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define MOD 1000000007
#define SIZE_1 2000005
#define SIZE_2 1000000
#define INT_BITS 32
typedef long long int ll;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<ll> vi;

set<ll> s;
ll mx = 400000000;

void backtrack(ll x) {
  if (s.find(x) != s.end())
    return;

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

  if (x == 0)
    for (int i = 1; i <= 9; i++)
      backtrack(i);

  else {
    int t = x % 10;

    if (t > 0)
      backtrack(x * 10 + (t - 1));

    backtrack(x * 10 + t);

    if (t < 9)
      backtrack(x * 10 + (t + 1));
  }
}

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

  backtrack(0);
  int k;
  cin >> k;
  while (k) {
    s.erase(s.begin());
    --k;
  }

  cout << *s.begin();

  return 0;
}


Error: TLE

Fixed submission:

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

#define MOD 1000000007
#define SIZE_1 2000005
#define SIZE_2 1000000
#define INT_BITS 32
typedef long long int ll;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<ll> vi;

bool isLunLun(string s) {
  for (int i = 0; i < s.length() - 1; i++)
    if (abs(s[i] - s[i + 1]) > 1)
      return false;

  return true;
}

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

  int k;
  vi v;
  for (int i = 1; i <= 9; i++)
    v.push_back(i);

  int t = 10;
  int cnt = 9;

  while (1) {
    if (isLunLun(to_string(t))) {
      cnt++;
      v.push_back(t);
    }
    if (cnt == 100000)
      break;
    t++;
  }

  cin >> k;
  cout << v[k - 1];

  return 0;
}