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

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(a) (a).begin(), (a).end()
typedef pair<int, int> P;
typedef long long ll;

vector<ll> lun;

void dfs(int d, ll now) {
  lun.push_back(now);

  if (d == 10)
    return;

  for (int i = -1; i <= 1; i++) {
    int add = now % 10 + i;
    if (add >= 0 && add <= 9)
      dfs(d + 1, now * 10 + add);
  }
}

int main() {
  int k;
  cin >> k;
  rep(i, 9) dfs(1, i + 1);
  sort(all(lun));
  dunk(lun[k - 1]);
  return 0;
}

Error: -6
/usr/include/c++/12/debug/vector:442:
In function:
    std::debug::vector<_Tp, _Allocator>::reference std::debug::vector<_Tp, 
    _Allocator>::operator[](size_type) [with _Tp = long long int; _Allocator 
    = std::allocator<long long int>; reference = long long int&; size_type = 
    long unsigned int]

Error: attempt to subscript container with out-of-bounds index 14, but 
container only holds 0 elements.

Objects involved in the operation:
    sequence "this" @ 0x7ffdde03baa0 {
      type = std::debug::vector<long long, std::allocator<long long> >;
    }


Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(a) (a).begin(), (a).end()
typedef pair<int, int> P;
typedef long long ll;

vector<ll> lun;

void dfs(int d, ll now) {
  lun.push_back(now);

  if (d == 10)
    return;

  for (int i = -1; i <= 1; i++) {
    int add = now % 10 + i;
    if (add >= 0 && add <= 9)
      dfs(d + 1, now * 10 + add);
  }
}

int main() {
  int k;
  cin >> k;
  vector<ll> lun;
  rep(i, 9) dfs(1, i + 1);
  sort(all(lun));
  dunk(lun[k - 1]);
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(a) (a).begin(), (a).end()
typedef pair<int, int> P;
typedef long long ll;

void dfs(int d, ll now, vector<ll> &lun) {
  lun.push_back(now);

  if (d == 10)
    return;

  for (int i = -1; i <= 1; i++) {
    int add = now % 10 + i;
    if (add >= 0 && add <= 9)
      dfs(d + 1, now * 10 + add, lun);
  }
}

int main() {
  int k;
  cin >> k;
  vector<ll> lun;
  rep(i, 9) dfs(1, i + 1, lun);
  sort(all(lun));
  dunk(lun[k - 1]);
  return 0;
}

Error: WA

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(a) (a).begin(), (a).end()

unsigned GetDigit(unsigned num) {
  unsigned digit = 0;
  while (num != 0) {
    num /= 10;
    digit++;
  }
  return digit;
}

int main() {
  int k;
  cin >> k;
  vector<int> lun(k);
  rep(i, k) lun[i] = 0;
  lun[0] = 1;
  rep(i, k) {
    if (lun[i] < 10)
      lun[i + 1] = i + 2;
    else {
      int keta = GetDigit(lun[i]);
      string str = to_string(lun[i]);
      rep(j, keta - 1) {
        if (str[keta - 1 - j] - '0' <= str[keta - 2 - j] - '0') {
          int add = 1;
          rep(k, j) { add *= 10; }
          lun[i + 1] = lun[i] + add;
          break;
        }
      }
      if (lun[i + 1] == 0) {
        int add = 1;
        rep(j, keta - 1) { add *= 10; }
        lun[i + 1] = lun[i] + add;
        break;
      }
    }
  }
  dunk(lun[k - 1]);
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
vector<int> v;
void cc(int p) {
  ++v[p];
  if (p == 0 and v[p] > 9) {
    v[0] = 1;
    v.push_back(0);
    return;
  }
  if (v[p] > 9 or (p and abs(v[p] - v[p - 1] > 1))) {
    cc(p - 1);
    v[p] = max(0, v[p - 1] - 1);
  }
  return;
}
int main() {
  v.push_back(1);
  int k;
  cin >> k;
  assert(k <= 100000 and k >= 1);
  while (--k > 0) {
    cc(v.size() - 1);
  }
  for (int i = 0; i < v.size(); ++i)
    cout << v[i];
  cout << endl;
  return 0;
}

Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
vector<int> v;
void cc(int p) {
  ++v[p];
  if (p == 0 and v[p] > 9) {
    v[0] = 1;
    v.push_back(0);
    return;
  }
  if (v[p] > 9 or abs(v[p] - v[p - 1] > 1)) {
    cc(p - 1);
    v[p] = max(0, v[p - 1] - 1);
  }
}
int main() {
  v.push_back(1);
  int k;
  cin >> k;
  assert(k <= 100000 and k >= 1);
  while (--k > 0) {
    cc(v.size() - 1);
  }
  for (int i = 0; i < v.size(); ++i)
    cout << v[i];
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define rep(i, a, n) for (ll i = a; i < n; i++)
#define per(i, a, n) for (ll i = n - 1; i >= a; i--)
#define fill0(n) setfill('0') << right << setw(n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const long double EPS = 0.0000000001;

vector<ll> bfs(int n) {
  queue<ll> q;
  vector<ll> ret;
  int count = 0;
  for (int i = 1; i < 10; i++) {
    q.push(i);
    ret.push_back(i);
    count++;
    if (count == n)
      return ret;
  }
  while (1) {
    ll now = q.front();
    q.pop();
    // string now = to_string(top);
    // char c = now[now.size()-1];
    for (int i = -1; i < 2; i++) {
      ll check = now % 10 + i;
      if (check == -1 or check == 10)
        continue;
      q.push(now * 10 + check);
      ret.push_back(now * 10 + check);
      count++;
      if (count == n)
        return ret;
    }
  }
}
int main() {
  int k;
  cin >> k;
  vector<ll> v = bfs(k);
  // // for(int i = 0; i < v.size(); i++)cout << v[i] << " ";
  // cout << endl;
  cout << v[k - 1] << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, a, n) for (ll i = a; i < n; i++)
#define per(i, a, n) for (ll i = n - 1; i >= a; i--)
#define fill0(n) setfill('0') << right << setw(n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const long double EPS = 0.0000000001;

vector<ll> bfs(int n) {
  queue<ll> q;
  vector<ll> ret;
  int count = 0;
  for (int i = 1; i < 10; i++) {
    q.push(i);
    ret.push_back(i);
    count++;
  }
  while (1) {
    ll now = q.front();
    q.pop();
    // string now = to_string(top);
    // char c = now[now.size()-1];
    for (int i = -1; i < 2; i++) {
      ll check = now % 10 + i;
      if (check == -1 or check == 10)
        continue;
      q.push(now * 10 + check);
      ret.push_back(now * 10 + check);
      count++;
      if (count == n)
        return ret;
    }
  }
}
int main() {
  int k;
  cin >> k;
  vector<ll> v = bfs(k);
  // // for(int i = 0; i < v.size(); i++)cout << v[i] << " ";
  // cout << endl;
  cout << v[k - 1] << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int k;
  cin >> k;
  vector<long long> a = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  for (long long i = 0; a.size() < k; i++) {
    for (int j : vector<int>({-1, 0, 1})) {
      int d = a.at(i) % 10 + j;
      if (0 <= d && d <= 9) {
        a.push_back(a.at(i) * 10 + d);
      }
    }
  }
  cout << a.at(k - 1) << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int K;
  cin >> K;
  vector<long long int> A = {1, 2, 3, 4, 5, 6, 7, 8, 9};

  for (int i = 0; A.size() < K; i++) {
    for (int j = -1; j <= 1; j++) {
      int C = A.at(i) % 10 + i;
      if (0 <= C && C <= 9) {
        A.push_back(A.at(i) * 10 + C);
      }
    }
  }

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

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

vector<long long> v;
void dfs(ll x, ll num, ll st, ll cc) {
  if (v.size() > 100050)
    return;
  if (num == 0)
    num += x;
  else {
    num *= 10;
    num += x;
  }
  if (cc > st)
    return;
  if (cc == st) {
    v.push_back(num);
    return;
  }
  if (x - 1 >= 0)
    dfs(x - 1, num, st, cc + 1);
  if (x + 1 <= 9)
    dfs(x + 1, num, st, cc + 1);
  dfs(x, num, st, cc + 1);
  return;
}

int main() {

  ll k;
  cin >> k;
  for (int i = 1; i <= 10; i++) {
    for (int j = 1; j <= 9; j++) {
      dfs(j, 0, i, 1);
    }
  }
  sort(v.begin(), v.end());
  cout << v[k - 1] << "\\n";
}


Error: 0

Fixed submission:

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

vector<long long> v;
void dfs(ll x, ll num, ll st, ll cc) {
  if (v.size() > 100050)
    return;
  if (num == 0)
    num += x;
  else {
    num *= 10;
    num += x;
  }
  if (cc > st)
    return;
  if (cc == st) {
    v.push_back(num);
    return;
  }
  if (x - 1 >= 0)
    dfs(x - 1, num, st, cc + 1);
  if (x + 1 <= 9)
    dfs(x + 1, num, st, cc + 1);
  dfs(x, num, st, cc + 1);
  return;
}

int main() {

  ll k;
  cin >> k;
  for (int i = 1; i <= 8; i++) {
    for (int j = 1; j <= 9; j++) {
      dfs(j, 0, i, 1);
    }
  }
  sort(v.begin(), v.end());
  cout << v[k - 1] << "\\n";
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {

  int k;
  cin >> k;
  vector<long long> a;

  for (int i = 1; i <= 9; i++)
    a.push_back(i);

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

    k -= a.size();
    vector<long long> old;
    swap(old, a);

    for (long long x : old) {
      for (int i = -1; i <= 1; i++) {
        int d = x % 10 + i;

        if (d < 0 || d > 9)
          continue;

        long long nx = x * 10 + d;
        a.push_back(nx);
      }
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {

  int k, i = 0;
  long long j = 1;
  cin >> k;

  while (1) {
    long long first = j;
    long long second = j;
    int digit = 0;
    int l = 0;
    bool flag = false;
    while (first) {
      first = first / 10;
      digit++;
    }

    int a[digit];
    while (second) {
      a[l] = second % 10;
      second = second / 10;
      l++;
    }

    // if(j > 1){
    if (j >= 10) {
      for (int c = 0; c < digit; c++) {
        if (c >= 1) {
          if (abs(a[c] - a[c - 1]) > 1) {
            // cout << j << " a[c] = " << a[c] << " a[c-1] = " << a[c-1] <<
            // endl;
            flag = true;
            break;
          }
        }
      }
    }

    if (flag == true) {
      j++;
      continue;
    } else
      i++;
    //}

    if (i == k) {
      cout << j << endl;
      break;
    }
    // cout << j << " " << i << endl;

    j++;
  }

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

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

#define SIZE_OF_ARRAY(array) sizeof(array) / sizeof(array[0])

int main() {
  int K;
  cin >> K;
  std::queue<long long> q;
  for (long long i = 1; i <= 9; i++) {
    q.push(i);
  }
  long long b;
  for (int k = 0; k < K; k++) {
    b = q.front();
    long long mod = b % 10;
    q.pop();
    if (mod != 0) {
      q.push(10 * b + mod - 1);
    }
    q.push(10 * b + (b % 10));
    if (mod != 9) {
      q.push(10 * b + mod + 1);
    }
  }
  cout << b;
}

Error: TLE

Fixed submission:

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

#define SIZE_OF_ARRAY(array) sizeof(array) / sizeof(array[0])

int main() {
  int K;
  cin >> K;
  std::vector<long long> q;
  for (long long i = 1; i <= 9; i++) {
    q.push_back(i);
  }
  long long ans;
  for (int k = 0; k < K; k++) {
    long long b = q.at(0);
    long long mod = b % 10;
    ans = b;
    q.erase(q.begin());
    if (mod != 0) {
      q.push_back(10 * b + mod - 1);
    }
    q.push_back(10 * b + (b % 10));
    if (mod != 9) {
      q.push_back(10 * b + mod + 1);
    }
  }
  cout << ans;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

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

// long long int nish[100005];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int index;
  cin >> index;
  vector<long long int> nish1;
  for (int i = 1; i <= 9; i++)
    nish1.push_back(i);

  int count = 9;
  int temp = index;

  int flag = 0;
  for (int i = 0; i < index && count < temp; i++) {
    vector<long long int> nish2;
    for (int j = 0; j < nish1.size(); j++) {
      int temp2 = nish1[j] % 10;
      if (temp2 > 0)
        nish2.push_back(nish1[j] * 10 + temp2 - 1);
      if (temp2 != 9)
        nish2.push_back(nish1[j] * 10 + temp2 + 1);
      nish2.push_back(nish1[j] * 10 + temp2);
    }
    int total = count;

    count += nish2.size();
    nish1.resize(nish2.size());
    for (int k = 0; k < nish2.size(); k++)
      nish1[k] = nish2[k];

    // cout<<nish1[2]<<endl;
    if (count >= temp) {
      // cout<<temp-total-1<<endl;
      sort(nish1.begin(), nish1.end());
      cout << nish1[temp - total - 1] << endl;
      flag = 1;
      break;
    }
  }
  if (!flag) {
    // cout<<"sdfs"<<endl;
    cout << nish1[index - 1] << endl;
  }
  return 0;
}


Error: -11

Fixed submission:

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

vector<long long int> nish;
void serve(long long int num) {
  if (nish.size() > 100005)
    nish.push_back(num);
  int temp = num % 10;
  if (temp != 0)
    serve(10 * num + temp - 1);
  serve(10 * num + temp);
  if (temp != 9)
    serve(10 * num + temp + 1);
}
int main() {
  for (int i = 1; i <= 9; i++)
    serve(i);
  sort(nish.begin(), nish.end());
  int index;
  cin >> index;
  cout << nish[index - 1] << endl;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(15) << x << endl;
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef long long LL;
typedef long double LD;
const LL mod = 1000000007;

LL k;
vector<LL> res;

void dfs(LL keta, vector<LL> &parray) {
  LL tmp, tmp2;
  vector<LL> carray;
  for (LL i = 0; i < parray.size(); i++) {
    tmp = parray[i] % 10;
    tmp2 = parray[i];
    if (tmp != 0 && tmp != 9) {
      tmp2 *= 10;
      res.push_back(tmp2 + tmp - 1);
      res.push_back(tmp2 + tmp);
      res.push_back(tmp2 + tmp + 1);
      carray.push_back(tmp2 + tmp - 1);
      carray.push_back(tmp2 + tmp);
      carray.push_back(tmp2 + tmp + 1);
    } else if (tmp == 0) {
      tmp2 *= 10;
      res.push_back(tmp2 + tmp);
      res.push_back(tmp2 + tmp + 1);
      carray.push_back(tmp2 + tmp);
      carray.push_back(tmp2 + tmp + 1);
    } else {
      tmp2 *= 10;
      res.push_back(tmp2 + tmp - 1);
      res.push_back(tmp2 + tmp);
      carray.push_back(tmp2 + tmp - 1);
      carray.push_back(tmp2 + tmp);
    }
  }
  sort(res.begin(), res.end());
  if (res.size() >= k)
    ;
  else {
    dfs(keta++, carray);
  }
}

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

  cin >> k;

  vector<LL> rarray;
  for (LL i = 1; i <= 9; i++) {
    rarray.push_back(i);
    res.push_back(i);
  }
  dfs(1, rarray);
  if (k < 10)
    cout << k << endl;
  else
    cout << res[k - 1] << endl;
}

Error: TLE

Fixed submission:

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

typedef long long LL;

int main(void) {
  LL k;
  int x = 13;
  bool f = true;
  int a[20];
  cin >> k;
  if (k <= 12)
    cout << k << endl;
  else {
    k -= 12;
    while (k != 0) {
      string s = to_string(x);
      for (int i = 0; i < s.size() - 1; i++) {
        if (abs(s[i] - s[i + 1]) <= 1)
          ;
        else
          f = false;
      }
      if (f) {
        k--;
      }
      f = true;
      x++;
    }
    cout << x - 1 << endl;
  }
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

const int N = 110;

int dp[N][N];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i <= 9; i++)
    dp[1][i] = 1;
  for (int i = 2; i <= 10; i++)
    for (int j = 0; j <= 9; j++)
      dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1] + dp[i - 1][j + 1];

  queue<int> ans;

  int l = 0, r = 0, flag = 0;

  for (int i = 1; i <= 10; i++) {
    for (int j = 1; j <= 9; j++) {
      if (n <= dp[i][j]) {
        l = i;
        r = j;
        flag = 1;
        break;
      }
      n -= dp[i][j];
    }
    if (flag == 1)
      break;
  }
  l--;
  ans.push(r);
  while (l != 0) {
    if (n <= dp[l][r - 1]) {
      r--;
      ans.push(r);
    } else {
      n -= dp[l][r - 1];
      if (n <= dp[l][r])
        ans.push(r);
      else {
        n -= dp[l][r];
        r++;
        ans.push(r);
      }
    }
    l--;
  }
  while (!ans.empty()) {
    int res = ans.front();
    cout << res;
    ans.pop();
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define maxn 1000000
#define maxx 100000
using namespace std;
typedef long long ll;
ll a[maxn];

bool vis[maxn];

bool check(ll x) {
  ll res = x;
  ll kk = 0;
  while (res != 0) {
    a[kk] = res % 10;
    res = res / 10;
    kk++;
  }
  for (ll i = 1; i < kk; i++) {
    if (a[i] - a[i - 1] == 1 || a[i] - a[i - 1] == -1 || a[i] - a[i - 1] == 0) {
      continue;
    } else {
      return false;
    }
  }
  return true;
}

int main() {
  ll k;
  cin >> k;
  for (ll i = 1; i <= 12; i++) {
    vis[i] = 1;
  }
  if (k <= 12) {
    cout << k << endl;
    return 0;
  } else {
    ll tot = 12;
    for (ll i = 20;; i++) {
      if (check(i))
        tot++;
      if (tot == k) {
        printf("%lld", i);
        return 0;
      }
    }
  }
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> vec;
signed Lunlun(int n, int A) {
  vec.push_back(A);
  if (n == 10) {
    return 0;
  }
  if (A % 10 != 0 && A % 10 != 9) {
    Lunlun(n + 1, A * 10 + A % 10 + 1);
    Lunlun(n + 1, A * 10 + A % 10 - 1);
    Lunlun(n + 1, A * 10 + A % 10);
    return 0;
  } else if (A % 10 == 0) {
    Lunlun(n + 1, A * 10 + 1);
    Lunlun(n + 1, A * 10);
    return 0;
  } else {
    Lunlun(n + 1, A * 10 + 8);
    Lunlun(n + 1, A * 10 + 9);
    return 0;
  }
}
signed main() {
  int K;
  cin >> K;
  for (int i = 1; i < 10; i++) {
    Lunlun(0, i);
  }
  sort(vec.begin(), vec.end());
  cout << vec[K - 1] << endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> vec;
signed Lunlun(int n, int A) {
  vec.push_back(A);
  if (n == 10) {
    return 0;
  }
  if (A % 10 != 0 && A % 10 != 9) {
    Lunlun(n + 1, A * 10 + A % 10 + 1);
    Lunlun(n + 1, A * 10 + A % 10 - 1);
    return 0;
  } else if (A % 10 == 0) {
    Lunlun(n + 1, A * 10 + 1);
    return 0;
  } else {
    Lunlun(n + 1, A * 10 + 8);
    return 0;
  }
}
signed main() {
  int K;
  cin >> K;
  for (int i = 1; i < 10; i++) {
    Lunlun(0, i);
  }
  sort(vec.begin(), vec.end());
  cout << vec[K - 1] << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <list>
#include <queue>
#include <vector>

using namespace std;
#define ll long long

queue<ll> Q;
int debug = 0;

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

  for (ll i = 1; i < 10; ++i) {
    Q.push(i);
  }

  /*
  while(!Q.empty()){
      cout << Q.front() << endl;
      Q.pop();
  }
  */

  ll ans;
  ll r;
  for (int i = 1; i < K + 1; ++i) {
    ans = Q.front();
    Q.pop();
    if (i == K)
      break;
    r = ans % 10;

    if (debug)
      cout << "pick..." << ans << endl;

    if (r != 0) {
      Q.push(10 * ans + r - 1);
      if (debug)
        cout << "push..." << 10 * ans + r - 1 << endl;
    }
    Q.push(10 * ans + r);
    if (debug)
      cout << "push..." << 10 * ans + r << endl;

    if (r != 9) {
      Q.push(10 * ans + r + 1);
      if (debug)
        cout << "push..." << 10 * ans + r + 1 << endl;
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
#define ll long long

// NG 10^9
ll Lun[100000000];
int debug = 0;

bool lunp(ll tst) {
  string st1;
  char prev, cur;
  st1 = to_string(tst);
  int keta;
  keta = ceil(log10(tst));
  if (keta == 1)
    return true;
  else
    prev = st1[0];
  for (int i = 1; i < keta; ++i) {
    cur = st1[i];
    if (abs(prev - cur) > 1)
      return false;
    prev = cur;
  }
  return true;
}

int main() {
  int K;
  int tmp;
  /*
  tmp = ceil(log10(12));
  cout << tmp << endl;
  tmp = ceil(log10(8));
  cout << tmp << endl;
  */
  cin >> K;
  if (debug)
    cout << "K..." << K << endl;

  Lun[0] = 1;

  ll tst;
  int i = 0;

  while (true) {
    if (i == K)
      break;
    tst = Lun[i];
    tst++;
    while (!lunp(tst))
      tst++;
    i++;
    Lun[i] = tst;
    if (debug) {
      cout << i << "..." << Lun[i] << endl;
    }
  }

  cout << Lun[i - 1] << endl;
}