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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1 << (n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;
}
int const INF = 1001001001;

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

  int K;
  cin >> K;
  queue<ll> que;
  rrep(i, 9) que.push(i);

  rep(i, K) {
    ll d = que.front();
    if (i == K - 1)
      cout << d << endl;
    que.pop();
    string s = to_string(d);
    int cur = s[SZ(s) - 1] - '0';
    if (cur != 0)
      que.push(10 * d + cur - 1);
    que.push(10 * d + cur);
    if (cur != 9)
      que.push(10 * d + cur + 1);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1 << (n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;
}
int const INF = 1001001001;

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

  int K;
  cin >> K;
  priority_queue<ll, vector<ll>, greater<ll>> que;
  rrep(i, 9) que.push(i);
  rrep(i, 18) que.push(pow(10, i));

  rep(i, K) {
    if (i == K - 1) {
      cout << que.top() << endl;
      return 0;
    }
    ll D = que.top();
    que.pop();
    string S = to_string(D);
    if (S[0] == '1') {
      que.push(stoll("1" + S));
      que.push(stoll("2" + S));
      rrep(i, 13) {
        ll r = pow(10, i);
        string ss = to_string(r);
        que.push(stoll(ss + S));
      }
    } else if (S[0] == '9') {
      que.push(stoll("8" + S));
      que.push(stoll("9" + S));
    } else {
      int d = S[0] - '0';
      string s1 = to_string(d - 1);
      string s2 = to_string(d + 1);
      que.push(stoll(s1 + S));
      que.push(stoll(s2 + S));
      que.push(stoll(S[0] + S));
    }
  }

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

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

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

  vector<vector<int>> v(10, vector<int>(10, 1));
  for (int i = 1; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      if (j == 0) {
        v[i][j] = v[i - 1][j] + v[i - 1][j + 1];
      } else if (j == 9) {
        v[i][j] = v[i - 1][j] + v[i - 1][j - 1];
      } else {
        v[i][j] = v[i - 1][j] + v[i - 1][j + 1] + v[i - 1][j - 1];
      }
    }
  }

  string s;
  int sum = 0;
  int memo;
  bool f = false;
  for (int i = 0; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      sum += v[i][j];
      if (sum >= k) {
        s.push_back(j + 48);
        memo = i - 1;
        f = true;
        k -= sum - v[i][j];
        break;
      }
    }
    if (f) {
      break;
    }
  }

  while (memo >= 0) {
    if (s[s.size() - 1] == '0') {
      k -= v[memo][0];
      if (k <= 0) {
        s.push_back('0');
        k += v[memo][0];
        memo--;
        continue;
      }
      k -= v[memo][1];
      if (k <= 0) {
        s.push_back('1');
        k += v[memo][1];
        memo--;
        continue;
      }
    }

    if (s[s.size() - 1] == 9) {
      k -= v[memo][8];
      if (k <= 0) {
        s.push_back('8');
        k += v[memo][8];
        memo--;
        continue;
      }
      k -= v[memo][9];
      if (k <= 0) {
        s.push_back('9');
        k += v[memo][9];
        memo--;
        continue;
      }
    }

    else {
      int num = s[s.size() - 1] - 48;
      k -= v[memo][num - 1];
      if (k <= 0) {
        s.push_back(num - 1 + 48);
        k += v[memo][num - 1];
        memo--;
        continue;
      }
      k -= v[memo][num];
      if (k <= 0) {
        s.push_back(num + 48);
        k += v[memo][num];
        memo--;
        continue;
      }
      k -= v[memo][num + 1];
      if (k <= 0) {
        s.push_back(num + 1 + 48);
        k += v[memo][num + 1];
        memo--;
        continue;
      }
    }
  }
  cout << s << endl;
}

Error: TLE

Fixed submission:

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

long long f(long long x) {
  if (x < 0) {
    x = x * (-1);
  }
  return x;
}

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

  long long count = 0;
  long long i = 1;

  while (count < n) {
    bool f = false;
    string s = to_string(i);
    if (s.size() == 1) {
      f = true;
    } else {
      for (int i = 0; i < s.size() - 1; i++) {
        if (s[i] - s[i + 1] <= 1 && s[i] - s[i + 1] >= -1) {
          f = true;
        } else {
          f = false;
          break;
        }
      }
    }
    if (f) {
      count++;
    }
    i++;
  }
  cout << i - 1 << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int k;
  cin >> k;
  queue<long long> lun;
  for (int i = 1; i <= 9; i++)
    lun.push(i);
  for (int i = 0; i < k - 1; i++) {
    long long a = lun.front();
    lun.pop();
    if (a % 10 == 0) {
      lun.push(10 * a);
      lun.push(10 * a + 1);
    } else if (a % 10 == 9) {
      lun.push(10 * a + 8);
      lun.push(10 * a + 9);
    } else {
      int b = a % 10;
      lun.push(10 * a + b - 1);
      lun.push(10 * a + b);
      lun.push(10 * a + b + 1);
    }
  }
  cout << lun.front() << endl;
}

Error: -11

Fixed submission:

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

int main() {
  int k;
  long long ans = 0;
  cin >> k;
  vector<vector<int>> a(100, vector<int>(10));
  for (int i = 0; i < 10; i++)
    a[0][i] = 1;
  int i = 1;
  int ka = k - 9;
  long long keta = 10;
  if (k <= 9)
    cout << k << endl;
  else {
    while (k > 0) {
      for (int j = 1; j < 9; j++)
        a[i][j] = a[i - 1][j] + a[i - 1][j - 1] + a[i - 1][j + 1];
      a[i][0] = a[i - 1][0] + a[i - 1][1];
      a[i][9] = a[i - 1][8] + a[i - 1][9];
      for (int j = 1; j < 10; j++) {
        ka -= a[i][j];
        if (ka <= 0) {
          ans += j * keta;
          break;
        }
      }
      keta *= 10;
      i++;
    }
    keta /= 10;
    i--;
    while (ka > 0) {
      for (int j = 1; j < 10; j++) {
        ka -= a[i][j];
        if (ka <= 0) {
          ans += j * keta;
          break;
        }
      }
      keta /= 10;
      i--;
    }
    cout << ans << endl;
  }
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define DIV 1000000007
using namespace std;
using ll = long long;

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

  if (K <= 9)
    cout << K << endl;

  else {
    ll temp;
    ll cnt = 0;
    queue<ll> q;
    for (ll i = 1; i <= 9; i++) {
      q.push(i);
    }

    cnt = 9;
    while (cnt != K) {
      ll a = q.front() % 10;
      for (ll i = max((ll)0, a - 1); i <= min((ll)9, a + 1); i++) {
        temp = 10 * q.front() + i;
        // cout << "temp=" << temp << endl;
        q.push(temp);
        cnt++;
        if (cnt == K) {
          cout << temp << endl;
          break;
        }
      }
      if (cnt == K) {
        break;
      }
      if (!q.empty())
        q.pop();
    }
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define DIV 1000000007
using namespace std;
using ll = long long;

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

  if (K <= 9)
    cout << K << endl;

  else {
    ll temp;
    ll ans;
    ll cnt = 0;
    queue<ll> q;
    for (ll i = 1; i <= 9; i++) {
      q.push(i);
    }

    cnt = 9;
    while (cnt != K) {
      ll a = q.front() % 10;
      for (ll i = max((ll)0, a - 1); i <= min((ll)9, a + 1); i++) {
        temp = 10 * q.front() + i;
        // cout << "temp=" << temp << endl;
        q.push(temp);
        cnt++;
        if (cnt == K) {
          cout << temp << endl;
        }
      }
      q.pop();
    }
  }
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define ST_ARR_LEN(array) (sizeof(array) / sizeof(*array))
#define MOD 1000000007

using namespace std;

using ll = long long;
const ll MAX = LLONG_MAX;
const ll MIN = LLONG_MIN;

typedef stack<ll> llStack;
typedef queue<ll> llQueue;
typedef vector<ll> llVector;
typedef list<ll> llList;

typedef struct S {
  int a;
  int b;
} Object;

int main() {
  ll N;
  cin >> N;

  llQueue q;
  for (int i = 1; i < 10; i++) {
    q.push(i);
  }
  ll a;
  for (int i = 0; i < N - 1; i++) {
    a = q.front();
    q.pop();
    if (a % 10 != 0) {
      q.push(10 * a + (a % 10) - 1);
    }
    q.push(10 * a + (a % 10));
    if (a % 10 != 9) {
      q.push(10 * a + (a % 10) + 1);
    }
  }

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define ST_ARR_LEN(array) (sizeof(array) / sizeof(*array))

typedef std::stack<int> IntStack;
typedef std::queue<int> IntQueue;
typedef std::vector<int> IntVector;
typedef std::list<int> IntList;

using namespace std;

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

  long long ans;
  int count = 0;
  long long n = 0;
  ostringstream oss;
  string str;
  bool lunlun = true;
  while (count < K) {
    n++;
    oss.str("");
    oss << n;
    str = oss.str();
    // cout << str << endl;
    for (int i = 0; i < ((int)str.size()) - 1; i++) {
      if (abs(str[i] - str[i + 1]) > 1) {
        lunlun = false;
        break;
      }
    }
    if (lunlun) {
      count++;
    }
    lunlun = true;
  }

  cout << n << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

// 大文字->小文字 tolower(),逆はtoupper()
// int a = stoi(c); 文字列をintへ
// 途中の出力をそのまま残さない
// 数値計算 個数以外はdouble
// map<キー,値> p は辞書。p[キー] = 値
// map 全探索
// auto begin = p.begin(), end = p.end();
// for (auto it = begin; it != end; it++) {}
// mapのキー：it->first mapのバリュー：it->second
// 絶対値 abs()
// 入力は空白で切れる
// 大文字判定 isupper(文字) 小文字判定 islower(文字)
// do{}while(next_permutation(ALL(配列)))
// while(N)で回すとき、Nはコピーを作っておく
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < N; i++)
#define ALL(a) (a).begin(), (a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
  ll dig = 0;
  while (N) {
    dig++;
    N /= K;
  }
  return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
  ll r;
  while (x % y) {
    r = x % y;
    x = y;
    y = r;
  }
  return y;
}

// nC2の計算
ll C(ll N) { return N * (N - 1) / 2; }

ll a(ll n, ll x) {
  ll r = pow(10, x);
  n = (n % r);
  n /= pow(10, x - 1);
  return n;
}

int main() {
  ll k;
  cin >> k;
  vector<ll> cue;
  for (int i = 1; i <= 9; i++)
    cue.push_back(i);
  while (1) {
    if (k <= cue.size()) {
      cout << cue[k - 1] << endl;
      return 0;
    }

    k -= cue.size();
    vector<ll> old;
    swap(old, cue);
    for (ll x : old) {
      for (int i = -1; i <= 1; i++) {
        int d = x % 10 + i;
        if (d < 0 || d > 9)
          continue;
        ll nx = x * 10 + d;
        cue.push_back(nx);
      }
    }
  }
}

Error: TLE

Fixed submission:

// 大文字->小文字 tolower(),逆はtoupper()
// int a = stoi(c); 文字列をintへ
// 途中の出力をそのまま残さない
// 数値計算 個数以外はdouble
// map<キー,値> p は辞書。p[キー] = 値
// map 全探索
// auto begin = p.begin(), end = p.end();
// for (auto it = begin; it != end; it++) {}
// mapのキー：it->first mapのバリュー：it->second
// 絶対値 abs()
// 入力は空白で切れる
// 大文字判定 isupper(文字) 小文字判定 islower(文字)
// do{}while(next_permutation(ALL(配列)))
// while(N)で回すとき、Nはコピーを作っておく
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < N; i++)
#define ALL(a) (a).begin(), (a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
  ll dig = 0;
  while (N) {
    dig++;
    N /= K;
  }
  return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
  ll r;
  while (x % y) {
    r = x % y;
    x = y;
    y = r;
  }
  return y;
}

// nC2の計算
ll C(ll N) { return N * (N - 1) / 2; }

ll a(ll n, ll x) {
  ll r = pow(10, x);
  n = (n % r);
  n /= pow(10, x - 1);
  return n;
}

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

  if (K >= 1 && K <= 9) {
    cout << K << endl;
    return 0;
  }

  ll n = 10;
  ll cnt = 9;
  while (true) {
    ll d = dig(n, 10);
    for (int i = 1; i <= d - 1; i++) {
      ll flag = 0;
      if (abs(a(n, i) - a(n, i + 1)) > 1) {
        break;
      } else if (flag == d - 2) {
        cnt++;
      }
      flag++;
    }

    if (cnt == K) {
      cout << n << endl;
      return 0;
    }
    n++;
  }
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ull unsigned long long

#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

bool isPalindrome(string s) {
  string t(s.rbegin(), s.rend());
  return s == t;
}

int main(void) {
  long K;
  long x;
  queue<long> q;
  cin >> K;
  for (long i = 1; i <= 9; i++)
    q.push(i);
  for (long i = 0; i < K; i++) {
    long mod, temp;
    x = q.front();
    mod = x % 10;
    temp = 10 * x + mod;
    q.pop();
    if (mod != 0)
      q.push(temp - 1);
    q.push(temp);
    if (mod != 9)
      q.push(temp + 1);
  }
  cout << x << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

#define ull unsigned long long

#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

bool isPalindrome(string s) {
  string t(s.rbegin(), s.rend());
  return s == t;
}

int main(void) {
  long K;
  long x;
  vector<long> queue = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  cin >> K;
  for (long i = 0; i < K; i++) {
    long mod, temp;
    x = queue.front();
    mod = x % 10;
    temp = 10 * x + mod;
    queue.erase(queue.begin());
    if (mod != 0)
      queue.push_back(temp - 1);
    queue.push_back(temp);
    if (mod != 9)
      queue.push_back(temp + 1);
  }
  cout << x << endl;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  int N;
  cin >> N;
  queue<ll> Q;
  vector<ll> Lun;
  ll tmp = 1;
  int arr[] = {-1, 0, 1};
  int *it = begin(arr);
  while (Lun.size() < N) {
    if (Lun.size() < 9) {
      Lun.push_back(tmp);
      Q.push(tmp);
      tmp++;
    } else {
      tmp = Q.front();
      if (tmp % 10 == 9) {
        Lun.push_back(tmp * 10 + tmp % 10 - 1);
        Lun.push_back(tmp * 10 + tmp % 10);
        Q.push(tmp * 10 + tmp % 10 - 1);
        Q.push(tmp * 10 + tmp % 10);
      } else if (tmp % 10 == 0) {
        Lun.push_back(tmp * 10 + tmp % 10);
        Lun.push_back(tmp * 10 + tmp % 10 + 1);
        Q.push(tmp * 10 + tmp % 10);
        Q.push(tmp * 10 + tmp % 10 + 1);
      } else {
        for (auto it = begin(arr); it != end(arr); ++it) {
          Lun.push_back(tmp * 10 + tmp % 10 + (*it));
          Q.push(tmp * 10 + tmp % 10 + (*it));
        }
      }
      Q.pop();
    }
  }
  cout << Lun[N - 1] << endl;
}

Error: TLE

Fixed submission:

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

bool isLun(ll N) {
  bool ret = false;
  while (!ret) {
    if (N < 10)
      ret = true;
    else if (abs(N % 10 - N % 100 / 10) > 1)
      break;
    N /= 10;
  }
  return ret;
}

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

  int N;
  cin >> N;
  int it = 0;
  ll now = 0;
  while (it != N) {
    now++;
    if (isLun(now))
      it++;
  }
  cout << now << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main(void) {
  int K, i, j = 0, count = 9;
  long long a[100005] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  scanf("%d", &K);
  for (i = 0; count < K; i++) {
    if (a[i] % 10 != 0) {
      a[count] = (long long)a[i] * 10 + a[i] % 10 - 1;
      count++;
    }
    a[count] = (long long)a[i] * 10 + a[i] % 10;
    count++;
    if (a[i] % 10 != 9) {
      a[count] = (long long)a[i] * 10 + a[i] % 10 + 1;
      count++;
    }
  }
  printf("%lld", a[K - 1]);
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>

int main(void) {
  unsigned int K, i, j = 0, count = 9, a[1005] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  scanf("%d", &K);
  for (i = 0; count < K; i++) {
    if (a[i] % 10 != 0) {
      a[count] = a[i] * 10 + a[i] % 10 - 1;
      count++;
    }
    a[count] = a[i] * 10 + a[i] % 10;
    count++;
    if (a[i] % 10 != 9) {
      a[i] * 10 + a[i] % 10 + 1;
      count++;
    }
  }
  printf("%d", a[K - 1]);
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
vector<long long> ans;

void dfs(long long x) {
  if (x > 3234566667)
    return;
  ans.push_back(x);
  for (int i = -1; i <= 1; i++) {
    int add = x % 10 + i;
    if (0 <= add && add <= 9) {
      dfs(x * 10 + add);
    }
  }
}

int main() {
  int K;
  cin >> K;
  for (long long i = 1; i < 10; i++)
    dfs(i);
  sort(ans.begin(), ans.end());
  cout << ans[K - 1] << endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = a; i <= b; i++)

vector<int> mang;

const int N = 1e5;

bool Try(string s) {
  int len = s.length() - 1;
  FOR(i, 0, len - 1)
  FOR(j, i + 1, len) {
    int so = s[i] - '0', so1 = s[j] - '0';
    if (abs(so - so1) > 1)
      return false;
  }
  return true;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  FOR(i, 1, N) {
    bool kt = Try(to_string(i));
    if (kt)
      mang.push_back(i);
  }
  cout << mang[n - 1];
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <bits/stdc++.h>
#include <string.h>
#include <vector>
// s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep_a(i, a, n) for (int i = a; i < n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

int main() {

  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++) {
        long long 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:



#include <bits/stdc++.h>
#include <string.h>
#include <vector>
// s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep_a(i, a, n) for (int i = a; i < n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

int main() {

  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++) {
        long long d = x * 10 + i;
        if (d < 0 || d > 9)
          continue;
        long long nx = x * 10 + d;
        a.push_back(nx);
      }
    }
  }

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

/*                    */
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
char to_char(int n) { return n + '0'; };
int to_int(char c) { return c - '0'; };
/*                    */

void solve(string s, int ord, int k);
int cnt = 0;

int main() {
  int k;
  cin >> k;
  int ord = 1;
  if (k < 10) {
    cout << k << endl;
    return 0;
  }
  cnt = 9;
  ord = 2;
  while (true) {
    for (int i = 1; i <= 9; i++) {
      solve(to_string(i), ord, k);
    }
    ord++;
  }
}

void solve(string s, int ord, int k) {
  if (s.size() == ord) {
    cnt++;
    if (cnt == k) {
      cout << s << endl;
      exit(0);
    }
    return;
  }
  for (int i = -1; i <= 1; i++) {
    int tmp = to_int(s.back()) + i;
    if (tmp < 0 || tmp > 9)
      continue;
    s.push_back(to_char(tmp));
    solve(s, ord, k);
    s.pop_back();
  }
}

Error: TLE

Fixed submission:

/*                    */
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
char to_char(int n) { return n + '0'; };
int to_int(char c) { return c - '0'; };
/*                    */

void solve(string s, int ord, int k);
int cnt = 0;

int main() {
  int k;
  cin >> k;
  int ord = 1;
  cnt = 9;
  ord = 2;
  while (true) {
    for (int i = 1; i <= 9; i++) {
      solve(to_string(i), ord, k);
    }
    ord++;
  }
}

void solve(string s, int ord, int k) {
  if (s.size() == ord) {
    cnt++;
    if (cnt == k) {
      cout << s << endl;
      exit(0);
    }
    return;
  }
  for (int i = -1; i <= 1; i++) {
    int tmp = to_int(s.back()) + i;
    if (tmp < 0 || tmp > 9)
      continue;
    s.push_back(to_char(tmp));
    solve(s, ord, k);
    s.pop_back();
  }
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (i = 0; i < n; i++)
// 2D::rep(i,j)rep(j,j)cin>>bin[i][j];
// vector<int> a(n)
#define A1 cout << "No" << endl
#define A2 cout << "Yes" << endl
#define A3 cout << ans << endl
#define AA(i) cout << i << endl
const int U = 2e5 + 5;
const ll MOD = 1000000007;
const int INF = 1001001001;

int main() {
  int K;
  cin >> K;
  int i = 0, j, k;
  vector<ll> ans = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  for (; i < K;) {
    j = i + 1;
    i = ans.size() - 1;
    for (j; j <= i; j++) {
      if ((ans[j] * 10 + ans[j] % 10 - 1) % 10 != 9)
        ans.push_back(ans[j] * 10 + ans[j] % 10 - 1);
      ans.push_back(ans[j] * 10 + ans[j] % 10);
      if ((ans[j] * 10 + ans[j] % 10 + 1) % 10 != 0)
        ans.push_back(ans[j] * 10 + ans[j] % 10 + 1);
    }
  }
  AA(ans[K]);
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int K;
  cin >> K;
  long long S = 0;
  int i = 0;
  for (; i < K;) {
    S++;
    string str = to_string(S);
    if (str.size() == 1) {
      i++;
    } else {
      for (int t = 0; t < str.size() - 1; t++) {
        int c = str[t], d = str[t + 1];
        int M = max(c, d);
        int m = min(c, d);
        if (M - m > 1) {
          break;
          S += 9;
        }
        if (t == str.size() - 2) {
          i++;
        }
      }
    }
  }
  cout << S << endl;
}