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

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

int main() {
  int k;
  cin >> k;
  queue<ll> q;
  rep(i, 9) q.push(i + 1);
  ll x;
  while (k--) {
    x = q.front();
    q.pop();
    if (x % 10 == 0) {
      q.push(x * 10);
      q.push(x * 10 + 1);
    } else if (x % 10 == 9) {
      q.push(x * 10 + 8);
      q.push(x * 10 + 9);
    } else {
      int y = x % 10;
      q.push(x * 10 + (y - 1));
      q.push(x * 10 + y);
      q.push(x * 10 + (y + 1));
    }
  }
  cout << x << endl;
}

Error: TLE

Fixed submission:

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

int check(ll x) {
  vector<int> keta;
  while (x != 0) {
    keta.push_back(x % 10);
    x /= 10;
  }
  bool ok = true;
  int n = keta.size();
  rep(i, n - 1) {
    if (abs(keta[i] - keta[i + 1]) >= 2)
      ok = false;
  }
  return ok;
}

int main() {
  int k;
  cin >> k;
  ll x = 0;
  while (k != 0) {
    x++;
    if (check(x))
      k--;
  }
  cout << x << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
priority_queue<ll, vector<ll>, greater<ll>> q;

int main() {
  ll K;
  cin >> K;
  for (int i = 1; i < 10; i++)
    q.push(i);
  for (int i = 1; i <= K; i++) {
    ll s = q.top();
    q.pop();
    if (i == K) {
      cout << s << endl;
      break;
    }
    int n = s % 10;
    for (int j = -1; j <= 1; j++) {
      if (n + j >= 0 && n + j <= 9) {
        q.push(n + j + s * 10);
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
  ll K;
  cin >> K;
  ll c = 0;
  for (ll i = 1; i <= 3234566667; i++) {
    bool f = true;
    string s = to_string(i);
    for (int j = 1; j < s.size(); j++) {
      if (abs(s[j] - s[j - 1]) > 1) {
        f = false;
        break;
      }
    }
    if (f)
      c++;
    if (c >= K) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <queue>
using namespace std;
queue<long> Q;
long lunlun(int j) { // j回目操作
  long this_front = Q.front();
  Q.pop();
  int x = this_front % 10;
  if (x != 0) {
    Q.push(this_front * 10 + x - 1);
  }
  Q.push(this_front * 10 + x);
  if (x != 9) {
    Q.push(this_front * 10 + x + 1);
  }
  return this_front;
}
int main() {
  int k;
  cin >> k;

  long this_num = 0;
  for (int i = 1; i <= 9; i++) { // 初期状態
    Q.push(i);
  }
  for (int i = 1; i <= k; i++) {
    this_num = lunlun(i);
  }

  cout << this_num << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;
int judge_lunlun(long X) {
  int flg = 1;
  int s = X % 10;
  long t = X / 10;
  int u = t % 10;
  while (1) {
    if (abs(s - u) > 1 && t > 0) {
      flg = 0;
      break;
    } else if (t == 0) {
      break;
    } else {
      s = u;
      t = t / 10;
      u = t % 10;
    }
  }
  return flg;
}

int main() {
  int k;
  cin >> k;
  int cnt = 0;
  long this_num = 0;
  while (cnt < k) {
    this_num++;
    if (judge_lunlun(this_num) == 1) {
      cnt++;
    }
  }
  cout << this_num << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int K;
  cin >> K;
  string A[K + 1];
  A[0] = "0";
  for (int i = 1; i <= K; i++) {
    string S = A[i - 1];
    int N = S.size() - 1;
    while (N > 0 && (S.at(N) == '9' || S.at(N - 1) < S.at(N)))
      N--;
    if (N == 0 && S.at(0) == '9')
      A[i] = to_string(stoi(S) + 1);
    else {
      S.at(N)++;
      for (N++; N < S.size(); N++)
        S.at(N) = max((char)(S.at(N - 1) - 1), '0');
      A[i] = S;
    }
  }
  cout << A[K] << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 0) >= this->size() (which is 0)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int K;
  cin >> K;
  string A[K + 1];
  A[0] = "0";
  for (int i = 1; i++; i <= K) {
    string S = A[i - 1];
    int N = S.size() - 1;
    while (N > 0 && (S.at(N) == '9' || S.at(N - 1) < S.at(N)))
      N--;
    if (S.at(0) == '9')
      A[i] = to_string(stoi(S) + 1);
    else {
      S.at(N)++;
      for (N++; N < S.size(); N++)
        S.at(N) = max((char)(S.at(N - 1) - 1), '0');
      A[i] = S;
    }
  }
  cout << A[K] << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

LL k, maxx = 9;

void bfs() {
  queue<pair<LL, LL>> q;
  q.push(make_pair(1ll, 1ll));
  q.push(make_pair(2ll, 2ll));
  q.push(make_pair(3ll, 3ll));
  q.push(make_pair(4ll, 4ll));
  q.push(make_pair(5ll, 5ll));
  q.push(make_pair(6ll, 6ll));
  q.push(make_pair(7ll, 7ll));
  q.push(make_pair(8ll, 8ll));
  q.push(make_pair(9ll, 9ll));
  while (!q.empty()) {
    LL djl = q.front().first;
    LL nums = q.front().second;
    q.pop();
    if (nums == k) {
      cout << djl << endl;
      exit(0);
    }
    if ((djl % 10) - 1 > -1) {
      maxx++;
      q.push(make_pair(djl * 10 + (djl % 10) - 1, maxx));
    }
    maxx++;
    q.push(make_pair(djl * 10 + (djl % 10), maxx));
    if ((djl % 10) + 1 < 10) {
      maxx++;
      q.push(make_pair(djl * 10 + (djl % 10) + 1, maxx));
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin >> k;
  bfs();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, t = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1;; i++) {
    bool flag = true;
    for (int j = i; j >= 10; j /= 10)
      if (abs(j % 10 - j % 100 / 10) > 1) {
        flag = false;
        break;
      }
    if (flag && ++t == n) {
      printf("%d\\n", i);
      break;
    }
  }
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int K;
  cin >> K;
  queue<long long> que;
  for (int i = 1; i < 10; ++i)
    que.push(i);
  for (int i = 0; i < K - 1; ++i) {
    long long s = que.front();
    que.pop();
    for (int j = -1; j <= 1; ++j) {
      long long add = (s % 10) + j;
      if (add >= 0 && add <= 9)
        que.push(s * 10 + add);
    }
  }
  cout << que.front() << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int k;
  cin >> k;
  queue<ll> a;
  for (int i = 1; i < 10; i++) {
    a.push(i);
  }
  rep(i, k - 1) {
    ll s = a.front();
    a.pop();
    for (int j = -1; i <= 1; j++) {
      ll add = (s % 10) + j;
      if (add >= 0 && add <= 9)
        a.push(s * 10 + add);
    }
  }
  cout << a.front() << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for (int i = 0; i < n; i++)

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll beki(ll a, ll b) {
  ll tmp = 1;
  REP(i, b) tmp *= a;
  return tmp;
}

ll K;
queue<ll> que;
ll ans[100010];
ll num = 0;
ll nowNum = 0;

int main() {

  cin >> K;
  if (K <= 9) {
    cout << K << endl;
    return 0;
  }
  // queに1の桁をつめる
  for (ll i = 1; i <= 9; i++) {
    que.push(i);
    ans[num] = i;
    num++;
    nowNum++;
  }

  // queにつまってるやつまでのをやるまでやる
  while (true) {
    // n回めはn桁のものをn+1桁にする
    for (ll i = 0; i < nowNum; i++) {
      for (ll j = -1; j <= 1; j++) {
        // ここで0、1、2とかを後ろにつける
        ll a = que.front();
        ll b = a % 10;

        if (b == 0 && j == -1)
          continue;
        if (b == 9 && j == 1)
          continue;
        que.push(a * 10 + b + j);
        ans[num] = a * 10 + b + j;
        num++;
        if (num == K) {
          cout << ans[K - 1] << endl;
          // REP(i, K) {
          //     cout << ans[i] << endl;
          // }
          return 0;
        }
      }
      que.pop();
    }

    // 最後にもどす
    nowNum = num - nowNum;
  }
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for (int i = 0; i < n; i++)

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll beki(ll a, ll b) {
  ll tmp = 1;
  REP(i, b) tmp *= a;
  return tmp;
}

ll K;
queue<ll> que;
ll ans[100010];
ll num = 0;
ll nowNum = 0;

int main() {

  cin >> K;

  // queに1の桁をつめる
  for (ll i = 1; i <= 9; i++) {
    que.push(i);
    ans[num] = i;
    num++;
    nowNum++;
  }

  // queにつまってるやつまでのをやるまでやる
  while (true) {
    // n回めはn桁のものをn+1桁にする
    for (ll i = 0; i < nowNum; i++) {
      for (ll j = -1; j <= 1; j++) {
        // ここで0、1、2とかを後ろにつける
        ll a = que.front();
        ll b = a % 10;

        if (b == 0 && j == -1)
          continue;
        if (b == 9 && j == 1)
          continue;
        que.push(a * 10 + b + j);
        ans[num] = a * 10 + b + j;
        num++;
        if (num == K) {
          cout << ans[K - 1] << endl;
          // REP(i, K) {
          //     cout << ans[i] << endl;
          // }
          return 0;
        }
      }
      que.pop();
    }

    // 最後にもどす
    nowNum = num - nowNum;
  }
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807;
const ll half_inf = 0x3f3f3f3f;
const ll inf = 0x7fffffff;
const ll mod = 998244353;
const ll maxn = 2000005;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll k, lun[100005] = {0}, a = 10, j = 1, one;
  scanf("%lld", &k);
  for (int i = 1; i <= 9; i++)
    lun[i] = i;
  while (a <= k) {
    one = lun[j] % 10;
    if (one != 0)
      lun[a++] = (lun[j] * 10) + one - 1;
    lun[a++] = (lun[j] * 10) + one;
    if (one != 9)
      lun[a++] = (lun[j] * 10) + one + 1;
    j++;
  }
  printf("%lld", lun[k]);
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807;
const ll half_inf = 0x3f3f3f3f;
const ll inf = 0x7fffffff;
const ll mod = 998244353;
const ll maxn = 2000005;
ll a[100005] = {0}, c = 1;
int judge(ll q) {
  string s = to_string(q);
  /*string s;
  stringstream flow;
  flow<<q;
  flow>>s;
  flow.clear();*/
  for (int i = 0; i < s.size() - 1; i++) {
    if (abs(s[i] - s[i + 1]) > 1)
      return 0;
  }
  return 1;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, k, b = 0, sum = 0;
  scanf("%d", &k);
  while (1) {
    if (judge(c)) {
      a[++b] = c;
      if (b == k)
        break;
    }

    c++;
  }

  printf("%d", a[k]);
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long K;
  cin >> K;
  queue<long long> q;
  for (int i = 1; i <= 9; i++) {
    q.push(i);
  }
  while (!q.empty()) {
    long long x = q.front();
    q.pop();
    K--;
    if (K == 0) {
      cout << x << endl;
      break;
    }
    for (int y = (x % 10) - 1; y <= (x % 10) + 1; y++) {
      if (y < 0 || y >= 10) {
        continue;
      }
      q.push(x * 10 + (long long)y);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int k;
int main() {
  cin >> k;
  int cnt = 0;
  for (int i = 1; cnt <= k; i++) {
    if (i <= 9) {
      cnt++;
      //			cout<<i<<" 1\\n";
    } else {
      int a[21];
      int ans = 0, res = 0, x = true, z = i;
      for (; z >= 10;) {
        a[ans++] = z % 10;
        z /= 10;
      }
      a[ans] = z;
      for (int j = 0; j < ans; j++) {
        //				cout<<"\\n"<<a[j]<<" ";
        if (abs(a[j] - a[j + 1]) > 1) {
          x = false;
          break;
        }
      }
      if (x == true) {
        cnt++;
        //				cout<<i<<" 2\\n";
      }
    }
    if (cnt == k) {
      cout << i;
      return 0;
    }
  }
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#include <bitset>        // bitset
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <deque>         // deque
#include <iostream>      // cout, endl, cin
#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
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef vector<ll> Vll;
typedef vector<Vll> VVll;

bool isLunLun(ll input) {
  bool lunlun = true;
  ll tmp = 0;
  ll tmp2 = 0;
  while (input) {
    tmp = input % 10;
    input /= 10;
    tmp2 = input % 10;
    if (input == 0) {
      break;
    }
    if (abs(tmp - tmp2) > 1) {
      lunlun = false;
    }
  }

  return lunlun;
}
int main() {
  ll K, count;
  cin >> K;
  queue<ll> q;
  ll x;
  rep(i, 9) { q.push(i + 1); }
  rep(i, K - 1) {
    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);
    }
  }
  cout << q.front() << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#include <bitset>        // bitset
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <deque>         // deque
#include <iostream>      // cout, endl, cin
#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
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;

bool isLunLun(ll input) {
  bool lunlun = true;
  ll tmp = 0;
  ll tmp2 = 0;
  while (input) {
    tmp = input % 10;
    input /= 10;
    tmp2 = input % 10;
    if (input == 0) {
      break;
    }
    if (abs(tmp - tmp2) > 1) {
      lunlun = false;
    }
  }

  return lunlun;
}
int main() {
  ll K, count;
  count = 0;
  ll i = 1;
  cin >> K;
  while (count != K) {
    if (isLunLun(i)) {
      count++;
      // cout << i << " ";
      if (count == K) {
        break;
      }
    }
    i++;
  }
  cout << i << endl;

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

#include <bits/stdc++.h>
using namespace std;
int k, i = -1;
vector<long long> vec = {};
void dfs(long long x, int a) {
  vec.push_back(x);
  if (x > 1000000000)
    return;
  if (x == 0) {
    for (int j = 1; j < 10; j++) {
      dfs(j, j);
    }
  } else {
    if (a != 0 && a != 9) {
      dfs(10 * x + a - 1, a - 1);
      dfs(10 * x + a, a);
      dfs(10 * x + a + 1, a + 1);
    }
    if (a == 0) {
      dfs(10 * x + 0, 0);
      dfs(10 * x + 1, 1);
    }
    if (a == 9) {
      dfs(10 * x + 8, 8);
      dfs(10 * x + 9, 9);
    }
  }
}

int main() {
  cin >> k;
  dfs(0, 0);
  sort(vec.begin(), vec.end());
  cout << vec[k] << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int k, i = -1;
vector<long long> vec = {};
void dfs(long long x, int a) {
  vec.push_back(x);
  if (x > 10000000)
    return;
  if (x == 0) {
    for (int j = 1; j < 10; j++) {
      dfs(j, j);
    }
  } else {
    if (a != 0 && a != 9) {
      dfs(10 * x + a - 1, a - 1);
      dfs(10 * x + a, a);
      dfs(10 * x + a + 1, a + 1);
    }
    if (a == 0) {
      dfs(10 * x + 0, 0);
      dfs(10 * x + 1, 1);
    }
    if (a == 9) {
      dfs(10 * x + 8, 8);
      dfs(10 * x + 9, 9);
    }
  }
}

int main() {
  cin >> k;
  dfs(0, 0);
  sort(vec.begin(), vec.end());
  cout << vec[k] << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
  ll k;
  cin >> k;
  if (k <= 9) {
    cout << k << endl;
    return 0;
  }
  ll cnt = 9;
  queue<ll> q;
  for (ll i = 1; i <= 9; i++)
    q.push(i);
  while (cnt != k) {
    ll cr = q.front();
    for (ll i = -1; i <= 1; i++) {
      ll d = cr % 10 + i;
      if (0 > d || d > 9)
        continue;
      ll nx = cr * 10 + d;
      q.push(nx);
      cnt++;
      if (cnt == k) {
        cout << q.back() << endl;
        return 0;
      }
    }
    q.pop();
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
bool runrun(long long n) {
  long long tmp = n % 10;
  n /= 10;
  while (n > 0) {
    int an = n % 10;
    if (abs(tmp - an) > 1)
      return false;
    else {
      tmp = an;
      n /= 10;
    }
  }
  return true;
}
int main(void) {
  int k;
  cin >> k;
  int cnt = 0;
  long long ans;
  for (long long i = 1; cnt < k; i++) {
    if (runrun(i)) {
      ans = i;
      cnt++;
    }
  }
  cout << ans << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  queue<long> lunlunsq;
  long count = 0;

  for (long lunlun = 1; lunlun <= 9; lunlun++) {
    count++;
    lunlunsq.push(lunlun);
    if (count == k) {
      cout << lunlun;
      return 0;
    }
  }

  while (true) {
    long baseLunlun = lunlunsq.front();
    lunlunsq.pop();
    long digit = baseLunlun % 10;

    if (digit > 0) {
      long lunlun = baseLunlun * 10 + digit - 1;
      count++;
      lunlunsq.push(lunlun);
      if (count == k) {
        cout << lunlun;
        return 0;
      }
    }

    {
      long lunlun = baseLunlun * 10 + digit;
      count++;
      lunlunsq.push(lunlun);
      if (count == k) {
        cout << lunlun;
        return 0;
      }
    }

    if (digit < 9) {
      long lunlun = baseLunlun * 10 + digit + 1;
      count++;
      lunlunsq.push(lunlun);
      if (count == k) {
        cout << lunlun;
        return 0;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;

bool IsLunlun(long n) {
  while (true) {
    long nextN = n / 10;
    if (nextN == 0) {
      break;
    }

    long digit = n % 10;
    long nextDigit = (n / 10) % 10;

    if (abs(digit - nextDigit) > 1) {
      return false;
    }

    n = nextN;
  }

  return true;
}

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

  long count = 0;
  long number = 0;
  while (count < k) {
    number++;
    if (IsLunlun(number)) {
      count++;
    }
  }

  cout << endl << number;

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

#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

// #include <stack>
// #include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";

ll K;
ll cnt[10][100];
ll maxCnt[10][100];
ll total;

int main() {

  vll count;
  int K;
  cin >> K;

  for (int ni = 1; ni < 10; ni++) {
    count.push_back(ni);
  }

  ll val;
  rep(ni, K) {
    val = count[ni];
    // cout << ni+1 << " : " << val << endl;
    // count.erase(count.begin());
    int key;
    key = val % 10;
    if (key > 0)
      count.push_back(val * 10 + (key - 1));
    count.push_back(val * 10 + key);
    if (key < 9)
      count.push_back(val * 10 + (key + 1));
  }
  cout << val << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

// #include <stack>
// #include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";

ll K;
ll cnt[10][100];
ll maxCnt[10][100];
ll total;

int main() {

  vll count;
  int K;
  cin >> K;

  for (int ni = 1; ni < 10; ni++) {
    count.push_back(ni);
  }

  ll val;
  rep(ni, K) {
    val = count[0];
    // cout << ni+1 << " : " << val << endl;
    count.erase(count.begin());
    int key;
    key = val % 10;
    if (key > 0)
      count.push_back(val * 10 + (key - 1));
    count.push_back(val * 10 + key);
    if (key < 9)
      count.push_back(val * 10 + (key + 1));
  }
  cout << val << endl;
}