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

#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

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

int main() {
  int K;
  cin >> K;
  vector<vector<ll>> lunlun(19);
  for (int i = 1; i <= 9; i++) {
    lunlun[1].push_back(i);
  }
  int num_of_digits = 2;
  while (true) {
    for (ll lun : lunlun[num_of_digits - 1]) {
      if (lun % 10 == 0) {
        lunlun[num_of_digits].push_back(lun * 10);
        lunlun[num_of_digits].push_back(lun * 10 + 1);
      } else if (lun % 10 != 9) {
        lunlun[num_of_digits].push_back(lun * 10 + (lun % 10 - 1));
        lunlun[num_of_digits].push_back(lun * 10 + lun % 10);
        lunlun[num_of_digits].push_back(lun * 10 + (lun % 10 + 1));
      } else {
        lunlun[num_of_digits].push_back(lun * 10 + 8);
        lunlun[num_of_digits].push_back(lun * 10 + 9);
      }
    }
    int num = K;
    for (vector<ll> lun_vec : lunlun) {
      if (num <= lun_vec.size()) {
        cout << lun_vec[num - 1] << endl;
        return 0;
      }
      num -= lun_vec.size();
    }
    num_of_digits++;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

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

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int K;
  cin >> K;
  queue<int64_t> q;
  int count = 0;
  int64_t start = 0;
  for (int i = 1; i <= 9; i++) {
    q.push(i);
  }
  while (count < K) {
    count++;
    start = q.front();
    // cout << count << " " << start << endl;
    q.pop();
    int f_num = start % 10;
    for (int i = -1; i <= 1; i++) {
      if (f_num + i >= 0 && f_num + i <= 9) {
        q.push(start * 10 + f_num + i);
        // cout << "push " << start * 10 + f_num + i << endl;
      }
    }
  }
  cout << start << endl;
}

Error: TLE

Fixed submission:

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

int serch(vector<vector<int>> M, int K, queue<int> &kans) {
  int count = 0;
  int ii = 1;
  int jj, ans, sans;
  for (int i = 0; i < 50; i++) {
    for (int j = 0; j < 9; j++) {
      count += M.at(i).at(j);
      if (K <= count) {
        cout << count << endl;
        for (int l = 0; l < i; l++) {
          ii *= 10;
        }
        jj = j + 1;
        ans = ii * jj;
        kans.push(ans);

        if (jj == 0) {
          ii = ii - 1;
          jj = 8;
        } else {
          jj -= 1;
        }

        return sans = K - ii * jj;
      }
    }
  }
  return 0;
}

int main() {
  int K;
  cin >> K;
  vector<vector<int>> M(50, vector<int>(9, 0));
  queue<int> kans;

  for (int j = 0; j < 9; j++) {
    M.at(0).at(j) = 1;
  }
  for (int j = 0; j < 8; j++) {
    M.at(1).at(j) = 3;
  }
  M.at(1).at(8) = 2;

  for (int i = 2; i < 50; i++) {
    for (int j = 0; j < 9; j++) {
      if (j >= 1 && j <= 7) {
        M.at(i).at(j) += M.at(i - 1).at(j - 1);
        M.at(i).at(j) += M.at(i - 1).at(j);
        M.at(i).at(j) += M.at(i - 1).at(j + 1);
      } else if (j == 8) {
        M.at(i).at(j) += M.at(i - 1).at(j - 1);
        M.at(i).at(j) += M.at(i - 1).at(j);
      } else {
        M.at(i).at(j) += M.at(i - 1).at(j);
        M.at(i).at(j) += M.at(i - 1).at(j + 1);
        M.at(i).at(j) += M.at(i - 1).at(8);
      }
    }
  }

  while (K != 0) {
    K = serch(M, K, kans);
  }

  int fans = 0;
  int i = 1;
  while (!kans.empty()) {
    fans += kans.front() * i;
    i *= 10;
    kans.pop();
  }

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

#include <iostream>

using namespace std;
using ll = long long;

constexpr int DMAX = 20;
ll nl[DMAX][10];

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

  int cnt{};

  for (int i = 0; i != 10; ++i) {
    nl[0][i] = 1;
    if (i)
      cnt += nl[0][i];
    if (cnt == k) {
      cout << i << endl;
      return 0;
    }
  }

  int d, i;
  for (d = 1; cnt < k; ++d) {
    for (i = 0; i != 10; ++i) {
      nl[d][i] = nl[d - 1][i];
      if (i != 9)
        nl[d][i] += nl[d - 1][i + 1];
      if (i) {
        nl[d][i] += nl[d - 1][i - 1];
        cnt += nl[d][i];
      }
      if (cnt >= k)
        break;
    }
  }

  ll ans = 0;
  int newcnt;

  while (d) {
    --d;
    ans *= 10;

    if (i != 9) {
      newcnt = cnt - nl[d][i + 1];
      if (newcnt < k) {
        i = i + 1;
        ans += i;
        continue;
      }
      cnt = newcnt;
    }

    newcnt = cnt - nl[d][i];
    if (newcnt < k) {
      ans += i;
      continue;
    }
    cnt = newcnt;

    if (i) {
      newcnt = cnt - nl[d][i - 1];
      if (newcnt < k) {
        i = i - 1;
        ans += i;
        continue;
      }
      cnt = newcnt;
    }
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;
using ll = long long;

bool is_lunlun(int x) {
  int d = x % 10;
  while (x) {
    int tmp = x % 10;
    if (abs(d - x % 10) > 1)
      return false;
    d = tmp;
    x /= 10;
  }
  return true;
}

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

  for (ll i = 1;; ++i) {
    if (is_lunlun(i))
      --k;
    if (!k) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define se second
#define fi first
#define rep(i, l, r) for (ll i = (ll)(l); i < (ll)(r); i++)
#define print(v)                                                               \\
  for (const auto itr : v) {                                                   \\
    cout << itr << ' ';                                                        \\
  }                                                                            \\
  cout << endl;
ll powermod(ll x, unsigned ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) {
      res = (res * x) % p;
    }
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
#define mod 1000000007
#define inf 1e18
using namespace std;
const ll INF = 1e18L + 5;
const ll maxn = 2e5 + 5;
ll ceel(ll a, ll b) {
  if (a % b == 0)
    return a / b;
  return a / b + 1;
}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); };

string change(string s) {
  // cout<<s<<"* ";
  if (count(s.begin(), s.end(), '9') == s.length()) {
    for (auto &it : s)
      it = '0';
    s += '1';
    reverse(s.begin(), s.end());
    return s;
  }
  ll i = s.length() - 1;
  while (i >= 1 and (s[i] == '9' or s[i] >= s[i - 1] + 1))
    i--;
  s[i]++;
  i++;
  for (; i < s.length(); i++)
    s[i] = max(char(s[i - 1] - 1), '0');
  return s;
}

int main() {

  ll i, j, k, n, m;
  cin >> k;
  string s = "1";
  string ans;
  while (k) {
    ans = s;
    s = change(s);
    k--;
  }

  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define se second
#define fi first
#define rep(i, l, r) for (ll i = (ll)(l); i < (ll)(r); i++)
#define print(v)                                                               \\
  for (const auto itr : v) {                                                   \\
    cout << itr << ' ';                                                        \\
  }                                                                            \\
  cout << endl;
ll powermod(ll x, unsigned ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) {
      res = (res * x) % p;
    }
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
#define mod 1000000007
#define inf 1e18
using namespace std;
const ll INF = 1e18L + 5;
const ll maxn = 2e5 + 5;
ll ceel(ll a, ll b) {
  if (a % b == 0)
    return a / b;
  return a / b + 1;
}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); };
ll calc(ll a) {
  string s;
  while (a != 0) {
    s += (a % 10) + '0';
    a = a / 10;
  }
  for (ll i = 0; i < s.length() - 1; i++) {
    if (abs(s[i] - s[i + 1]) > 1)
      return 0;
  }
  return 1;
}

int main() {

  ll i, j, k, n, m;
  cin >> k;
  i = 1;
  while (k) {
    if (calc(i))
      k--;
    i++;
  }
  cout << i - 1;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fast()                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define input() freopen("G:/daily practise/in0.txt", "r", stdin)
#define output() freopen("G:/daily practise/out0.txt", "w", stdout)
int main() {
  fast();
  set<ll> st = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  std::vector<ll> v;
  std::map<ll, bool> mp;
  while (!st.empty()) {
    ll f = *st.begin();
    mp[f] = 1;
    st.erase(st.begin());
    v.push_back(f);
    ll tmp = f * 10 * 1LL + f % 10;
    if (mp.count(tmp) == 0)
      st.insert(tmp);
    if (mp.count(tmp + 1) == 0 && tmp % 10 != 9)
      st.insert(tmp + 1);
    if (mp.count(tmp - 1) == 0 && tmp % 10 != 0)
      st.insert(tmp - 1);
    if (v.size() > 1e5)
      break;
  }
  ll k;
  cin >> k;
  cout << v[k - 1] << endl;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fast()                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define input() freopen("G:/daily practise/in0.txt", "r", stdin)
#define output() freopen("G:/daily practise/out0.txt", "w", stdout)
int main() {
  fast();
#ifndef ONLINE_JUDGE
  input();
  output();
#endif
  set<ll> st = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  std::vector<ll> v;
  std::map<ll, bool> mp;
  while (!st.empty()) {
    ll f = *st.begin();
    mp[f] = 1;
    st.erase(st.begin());
    v.push_back(f);
    ll tmp = f * 10 * 1LL + f % 10;
    if (mp.count(tmp) == 0)
      st.insert(tmp);
    if (mp.count(tmp + 1) == 0 && f % 10 != 9)
      st.insert(tmp + 1);
    if (mp.count(tmp - 1) == 0 && f % 10 != 0)
      st.insert(tmp - 1);
    if (v.size() > 1e5)
      break;
  }
  ll k;
  cin >> k;
  cout << v[k - 1] << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long k, ans = 0, cnt = 0, x[100100] = {0};
int dfs(long long s, long long tmp) {
  if (s <= 3234566667 && tmp != -1) {
    x[cnt - 1] = s;
  } else if (s > 3234566667)
    return 0;
  if (cnt == 100000) {
    return 0;
  }
  if (cnt > 100000)
    return 0;
  long long a, b, c;
  if (cnt == 0) {
    cnt++;
    dfs(1, 1);
    cnt++;
    dfs(2, 2);
    cnt++;
    dfs(3, 3);
    cnt++;
    dfs(4, 4);
    cnt++;
    dfs(5, 5);
    cnt++;
    dfs(6, 6);
    cnt++;
    dfs(7, 7);
    cnt++;
    dfs(8, 8);
    cnt++;
    dfs(9, 9);
  } else if (tmp == 0) {
    a = s * 10;
    b = s * 10 + 1;
    if (a <= 3234566667) {
      cnt++;
      dfs(a, 0);
    } else
      return 0;
    if (b <= 3234566667) {
      cnt++;
      dfs(b, 1);
    } else
      return 0;
  } else if (tmp == 9) {
    a = s * 10 + 8;
    b = s * 10 + 9;
    if (a <= 3234566667) {
      cnt++;
      dfs(a, 8);
    }
    if (b <= 3234566667) {
      cnt++;
      dfs(b, 9);
    }
  } else {
    a = s * 10 + (tmp - 1);
    b = s * 10 + tmp;
    c = s * 10 + (tmp + 1);
    if (a <= 3234566667) {
      cnt++;
      dfs(a, tmp - 1);
    } else
      return 0;
    if (b <= 3234566667) {
      cnt++;
      dfs(b, tmp);
    } else
      return 0;
    if (c <= 3234566667) {
      cnt++;
      dfs(c, tmp + 1);
    } else
      return 0;
  }
}
int main() {
  long long i;
  cin >> k;
  dfs(0, -1);
  sort(x, x + 100000);
  ans = x[k - 1];

  cout << ans << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long k, ans = 0, cnt = 1;
int dfs(long long s, long long tmp) {
  if (cnt == k) {
    ans = s;
    return 0;
  }
  long long a, b, c;
  if (tmp == 0) {
    a = s * 10;
    b = s * 10 + 1;
    cnt++;
    dfs(a, 0);
    cnt++;
    dfs(b, 1);
  } else {
    a = s * 10 + (tmp - 1);
    b = s * 10 + tmp;
    c = s * 10 + (tmp + 1);
    cnt++;
    dfs(a, tmp - 1);
    cnt++;
    dfs(b, tmp);
    cnt++;
    dfs(c, tmp + 1);
  }
}
int main() {
  cin >> k;
  dfs(1, 1);
  cnt++;
  dfs(2, 2);
  cnt++;
  dfs(3, 3);
  cnt++;
  dfs(4, 4);
  cnt++;
  dfs(5, 5);
  cnt++;
  dfs(6, 6);
  cnt++;
  dfs(7, 7);
  cnt++;
  dfs(8, 8);
  cnt++;
  dfs(9, 9);

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

#include <bits/stdc++.h>
using namespace std;
queue<long long> q;
int main() {
  int K;
  cin >> K;
  for (int i = 1; i < 10; i++) {
    q.push(i);
  }
  while (K--) {
    long long x = q.front();
    q.pop();
    if (K == 0) {
      cout << x << endl;
      return 0;
    }
    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);
    }
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long a[10005];
void biao() {
  int t = 13;
  for (int i = 1; i <= 12; i++)
    a[i] = i;
  long long x;
  long long g3 = 13;
  int g1, g2;
  while (t <= 100000) {
    x = g3;
    g1 = x % 10;
    x /= 10;
    while (x > 0) {
      g2 = x % 10;
      if (abs(g1 - g2) > 1)
        goto x1;
      x /= 10;
      g1 = g2;
    }
    a[t++] = g3;
  x1:;
    g3++;
  }
}
int main() {
  int k;
  cin >> k;
  biao();
  cout << a[k];
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  vector<long long> result, tmp;
  for (int i = 1; i <= 9; i++) {
    result.push_back(i);
    tmp.push_back(i);
  }
  for (int i = 0; i < 9; i++) {
    vector<long long> tmp2 = tmp;
    tmp.clear();
    for (int j = 0; j < tmp2.size(); j++) {
      long long num = tmp2[j] * 10 + tmp2[j] % 10;
      if (tmp2[j] % 10 != 0) {
        tmp.push_back(num - 1);
        result.push_back(num - 1);
      }
      tmp.push_back(num);
      result.push_back(num);
      if (tmp2[j] % 10 != 9) {
        tmp.push_back(num + 1);
        result.push_back(num + 1);
      }
    }
  }
  int n;
  cin >> n;
  cout << result[n - 1] << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long long k;
  cin >> k;
  long long i = 1;
  long long cnt = 0;
  string str;
  while (1) {
    str = to_string(i);
    if (str.length() == 1) {
      cnt++;
    } else {
      bool check = true;
      for (long long j = 0; j < str.length() - 1; j++) {
        if (str[j + 1] > str[j] + 1 || str[j + 1] < str[j] - 1) {
          check = false;
          break;
        }
      }
      if (check) {
        cnt++;
      }
    }
    if (cnt == k) {
      cout << i << endl;
      break;
    }
    i++;
  }
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, count = 0;
  cin >> n;
  int i;
  queue<string> q;
  for (i = 1; i < 10; i++)
    q.push(to_string(i));

  while (1) {
    int m = q.size(), i;

    for (i = 0; i < m; i++) {
      string s = q.front();
      q.pop();
      if (++count == n) {
        cout << s;
        return 0;
      }

      if (s.back() == '0') {
        q.push(s + '0'), q.push(s + '1');
      } else if (s.back() == '9') {
        q.push(s + '8'), q.push(s + '9');
      }

      else {
        q.push(s + (char)(s.back() - 1));
        q.push(s + (char)(s.back()));
        q.push(s + (char)(s.back() + 1));
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>

int abss(int x) {
  if (x < 0)
    return (-1) * x;
  else
    return x;
}

int islunlun(long long x) {
  if (x >= 1 && x <= 9)
    return 1;
  else {
    int left = x % 10;
    while (x >= 10) {
      x /= 10;
      int prev = x % 10;
      // printf("\\n%d %d",prev,left);
      if (abss(prev - left) > 1)
        return 0;
      left = prev;
    }

    return 1;
  }
}
int main() {
  int k;
  long long i;
  scanf("%d", &k);
  for (i = 1;; i++) {

    // 将他转换为字符串数组
    if (islunlun(i)) {
      // printf("%d ",i);
      k--;
    }
    if (k <= 0) {
      printf("%d", i);
      break;
    }
  }
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define Sort(v, n) sort(v, v + n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout << "Yes";
#define cN cout << "No";
#define cA(a) cout << a;
const ll MOD = 1000000007;

int main() {
  ll k;
  cin >> k;
  ll kosuu = 0;
  ll start = 0;
  vector<ll> v; // keta,suuzi
  for (ll i = 1; i < 10; i++) {
    v.push_back(i);
    kosuu++;
    if (kosuu == k) {
      cout << i;
      return 0;
    }
  }
  while (1) {
    for (ll i = start; i < v.size(); i++) {
      if (v[i] % 10 == 0) {
        kosuu++;
        v.push_back(v[i] * 10);
        if (kosuu == k) {
          cout << v[i] * 10;
          return 0;
        }
        kosuu++;
        v.push_back(v[i] * 10 + 1);
        if (kosuu == k) {
          cout << v[i] << 1;
          return 0;
        }
      } else if (v[i] % 10 == 9) {
        kosuu++;
        v.push_back(v[i] * 10 + 8);
        if (kosuu == k) {
          cout << v[i] << 8;
          return 0;
        }
        kosuu++;
        v.push_back(v[i] * 10 + 9);
        if (kosuu == k) {
          cout << v[i] << 9;
          return 0;
        }
      } else {
        kosuu++;
        v.push_back(v[i] * 10 + (v[i] % 10) - 1);
        if (kosuu == k) {
          cout << v[i] << (v[i] % 10) - 1;
          return 0;
        }
        kosuu++;
        v.push_back(v[i] * 10 + (v[i] % 10));
        if (kosuu == k) {
          cout << v[i] << (v[i] % 10);
          return 0;
        }
        kosuu++;
        v.push_back(v[i] * 10 + (v[i] % 10) + 1);
        if (kosuu == k) {
          cout << v[i] << (v[i] % 10) + 1;
          return 0;
        }
      }
      start = v.size();
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define Sort(v, n) sort(v, v + n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout << "Yes";
#define cN cout << "No";
#define cA(a) cout << a;
const ll MOD = 1000000007;

int ketame(ll n, ll keta) {
  n = n / pow(10, keta - 1);
  return n % 10;
}

int ketasuu(int n) {
  int res = 0;
  while (n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int main() {
  int k, ans = 0;
  cin >> k;
  for (ll i = 1; i < 3234566667; i++) {
    bool f = 1;
    for (ll j = 1; j < ketasuu(i); j++) {
      if (abs(ketame(i, j) - ketame(i, j + 1)) > 1) {
        f = 0;
      }
    }
    if (f) {
      ans++;
    }
    if (ans == k) {
      cout << i;
      return 0;
    }
  }
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  long long arr[100001];
  int ind1, ind2;
  ind1 = 0;
  ind2 = 1;
  for (int i = 1; i < 10; i++) {
    arr[i] = i;
    ind1++;
  }
  int cur = ind1;
  for (int j = 0; j < 8; j++) {
    for (int i = ind2; i <= ind1; i++) {
      int a = arr[i] % 10;
      if (a != 0) {
        arr[++cur] = arr[i] * 10 + a - 1;
      }
      arr[++cur] = arr[i] * 10 + a;
      if (a != 9) {
        arr[++cur] = arr[i] * 10 + a + 1;
      }
    }
    ind2 = ind1 + 1;
    ind1 = cur;
  }
  for (int i = ind2; i <= ind1 && cur < 100000; i++) {
    int a = arr[i] % 10;
    if (a != 0) {
      arr[++cur] = arr[i] * 10 + a - 1;
    }
    arr[++cur] = arr[i] * 10 + a;
    if (a != 9) {
      arr[++cur] = arr[i] * 10 + a + 1;
    }
  }
  // for(int i=1;i<20;i++)cout<<arr[i]<<endl;
  // cout<<n<<endl;
  cout << arr[n] << endl;
  return 0;
}


Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  long long arr[100001];
  int ind1, ind2;
  ind1 = 0;
  ind2 = 1;
  for (int i = 1; i < 10; i++) {
    arr[i] = i;
    ind1++;
  }
  int cur = ind1;
  for (int j = 0; j < 8; j++) {
    for (int i = ind2; i <= ind1; i++) {
      int a = arr[i] % 10;
      if (a != 0) {
        arr[++cur] = arr[i] * 10 + a - 1;
      }
      arr[++cur] = arr[i] * 10 + a;
      if (a != 9) {
        arr[++cur] = arr[i] * 10 + a + 1;
      }
    }
    ind2 = ind1 + 1;
    ind1 = cur;
  }
  for (int i = ind2; i <= ind1 && cur < 100001; i++) {
    int a = arr[i] % 10;
    if (a != 0) {
      arr[++cur] = arr[i] * 10 + a - 1;
    }
    arr[++cur] = arr[i] * 10 + a;
    if (a != 9) {
      arr[++cur] = arr[i] * 10 + a + 1;
    }
  }
  // for(int i=1;i<20;i++)cout<<arr[i]<<endl;
  // cout<<n<<endl;
  cout << arr[n] << endl;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int K;
  cin >> K;
  queue<int64_t> que;
  // push 1~9 numbers firstly
  for (int i = 1; i < 10; i++) {
    que.push(i);
  }
  int count = 0;
  int64_t print_num;
  while (true) {
    int64_t x = que.front();
    que.pop();
    count += 1;
    if (count == K) {
      print_num = x;
      break;
    }
    if (x % 10 == 0) {
      que.push(x * 10);
      que.push(x * 10 + 1);
    } else if (x % 10 == 9) {
      que.push(x * 10 + (x % 10 - 1));
      que.push(x * 10 + x % 10);
    } else {
      que.push(x * 10 + (x % 10 - 1));
      que.push(x * 10 + x % 10);
      que.push(x * 10 + (x % 10 + 1));
    }
  }
  cout << print_num << endl;
}

Error: TLE

Fixed submission:

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

bool lunlun(int64_t num) {
  if (num < 10) {
    return true;
  }
  string s_num = to_string(num);
  int64_t keta = s_num.size();
  // out << keta << endl;
  int64_t lunlun_count = 0;
  for (int64_t j = 0; j < (keta - 1); j++) {
    if (num < 10)
      break;
    int64_t zyu = (num % 100) / 10;
    int64_t iti = num % 10;
    if (abs(zyu - iti) <= 1) {
      lunlun_count += 1;
      num = num / 10;
    } else {
      return false;
    }
  }
  if (lunlun_count == (keta - 1))
    return true;
  else
    return false;
}

int main() {
  int K;
  cin >> K;
  int64_t lunlun_num;
  int lunlun_count;
  for (int64_t i = 1; i < 10000000000000000; i++) {
    if (i < 10) {
      lunlun_count += 1;
      continue;
    }
    string s_num = to_string(i);
    int keta = s_num.size();
    int max_keta = i / pow(10, keta - 1);
    int max_1_keta = (i - (max_keta * pow(10, keta - 1))) / pow(10, keta - 2);
    if (abs(max_keta - max_1_keta) > 1) {
      if (max_keta == 1) {
        i = (max_keta + 1) * pow(10, keta - 1);
      } else {
        if ((max_keta - max_1_keta) >= 2) {
          i = (max_keta + 1) * pow(10, keta - 1);
        }
      }
    }
    bool judge = lunlun(i);
    if (judge) {
      lunlun_count += 1;
      // cout << lunlun_count << endl;
      // cout << i << endl;
    }
    if (lunlun_count == K) {
      lunlun_num = i;
      break;
    }
  }
  cout << lunlun_num << endl;
}