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

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

vector<INT> v;
set<INT> s;

INT fun(INT n, INT k) {
  INT a, b;
  a = n % 10;
  if (a != 0) {
    if (binary_search(v.begin(), v.end(), n * 10 + a - 1) == false) {
      v.push_back(n * 10 + a - 1);
      s.insert(n * 10 + a - 1);
      k++;
    }
  }
  if (binary_search(v.begin(), v.end(), n * 10 + a) == false)
    v.push_back(n * 10 + a), k++, s.insert(n * 10 + a);
  if (a != 9 && binary_search(v.begin(), v.end(), n * 10 + a + 1) == false)
    v.push_back(n * 10 + a + 1), k++, s.insert(n * 10 + a + 1);
  return k;
}

int main() {
  INT n, i, a, b, c, k;
  scanf("%lld", &n);
  for (k = 1; k <= 8; k++) {
    v.push_back(k);
    s.insert(k);
  }
  v.push_back(k);
  s.insert(k);

  for (i = 0; true; i++) {
    k = fun(v[i], k);
    if (k >= n)
      break;
  }

  sort(v.begin(), v.end());
  /*for(i=0;i<n;i++)
      cout<<v[i]<<" ";
  cout<<endl<<s.size()<<" "<<v.size()<<endl;*/
  printf("%lld\\n", v[n - 1]);
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#define endl '\\n'
#define debug(x) cout << "This is " << x << '\\n'
#define INF 0x3f3f3f3f
#define DOF 0x7f7f7f7f
#define mem(a, b) memset(a, b, sizeof(a))
#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef long long ll;
using namespace std;
const int maxn = 1e5 + 10;

bool get_num(ll n) {
  ll b[20];
  ll cnt = 0;
  while (n) {
    b[++cnt] = n % 10;
    n /= 10;
  }
  for (int i = cnt; i >= 2; --i) {
    if (abs(b[i] - b[i - 1]) > 1)
      return false;
  }
  return true;
}
int main() {
  ll k;
  cin >> k;
  //    ll cnt=0;
  if (k <= 9)
    cout << k << endl;
  else {
    ll cnt = 9;
    for (int i = 10; i <= 3234566667; ++i) {
      if (get_num(i))
        ++cnt;
      if (cnt == k) {
        cout << i << endl;
        break;
      }
    }
  }
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

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

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

  queue<ll> q;
  for (int i = 1; i < 10; i++) {
    q.push(i);
  }

  ll ans = 0;
  for (int i = 1; i <= K; i++) {
    if (i == K)
      break;

    ll a = q.front();
    q.pop();

    if (a % 10 == 0) {
      q.push(a * 10);
      q.push(a * 10 + 1);
    } else if (a % 10 == 9) {
      q.push(a * 10 + 8);
      q.push(a * 10 + 9);
    } else {
      q.push(a * 10 + (a % 10) - 1);
      q.push(a * 10 + (a % 10));
      q.push(a * 10 + (a % 10) + 1);
    }
  }

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

Error: 0

Fixed submission:

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

int main() {
  long long INF = 1000000000000000;

  int K;
  cin >> K;

  vector<long long> Lun(K + 1);
  Lun.at(0) = 0;
  Lun.at(1) = 1;
  Lun.at(2) = 2;
  Lun.at(3) = 3;
  Lun.at(4) = 4;
  Lun.at(5) = 5;
  Lun.at(6) = 6;
  Lun.at(7) = 7;
  Lun.at(8) = 8;
  Lun.at(9) = 9;

  for (int i = 10; i <= K; i++) {
    long long x = Lun.at(i - 1);
    for (long long j = x + 1; j < INF; j++) {
      vector<int> A(20);
      int a = j;
      int Q = 0;
      for (int k = 0; k < INF; k++) {
        A.at(k) = a % 10;
        a = a / 10;
        if (a == 0) {
          Q = k;
          break;
        }
      }

      int CT = 0;
      for (int l = 0; l < Q; l++) {
        if (abs(A.at(l) - A.at(l + 1)) > 1) {
          CT = 1;
          break;
        } else {
          continue;
        }
      }

      if (CT == 0) {
        Lun.at(i) = j;
        break;
      } else {
        continue;
      }
    }
  }

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

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

int main() {
  int n;
  cin >> n;
  queue<long int> qu;
  for (long int i = 1; i < 10; i++)
    qu.push(i);

  long ans;
  while (n--) {
    ans = qu.front();
    qu.pop();
    if (ans % 10 != 0)
      qu.push(ans * 10 + ans % 10 - 1);
    qu.push(ans * 10 + ans % 10);
    if (ans % 10 != 9)
      qu.push(ans * 10 + ans % 10 + 1);
  }
  cout << ans;
}


Error: TLE

Fixed submission:

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

bool Lunner(int n) {
  if (n <= 12)
    return true;
  int i = 0;
  int arr[7] = {0};
  while (n) {
    arr[i] = n % 10;
    i++;
    n /= 10;
  }
  for (int j = 1; j < i; j++) {
    if (abs(arr[j] - arr[j - 1]) > 1)
      return false;
  }
  return true;
}

int main() {
  int n, c = 0, k = 1;
  cin >> n;
  while (c != n) {
    if (Lunner(k))
      c++;
    k++;
  }
  cout << k - 1;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  queue<ll> q;
  for (int i = 1; i <= 9; i++) {
    q.push(i);
  }

  ll ans;
  rep(ki, k) {
    ll a = q.front();
    q.pop();
    ans = a;
    if (a % 10 == 0) {
      q.push(a * 10 + 0);
      q.push(a * 10 + 1);
    } else if (a % 10 == 9) {
      q.push(a * 10 + 8);
      q.push(a * 10 + 9);
    } else {
      q.push(a * 10 + a % 10 - 1);
      q.push(a * 10 + a % 10);
      q.push(a * 10 + a % 10 + 1);
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int K;
  cin >> K;
  vector<int64_t> a;
  int64_t i = 1;
  while (a.size() != K) {
    string s = to_string(i);
    vector<int> b;
    for (int j = 0; j < s.size(); j++) {
      string y = to_string(s.at(j));
      int x = stoi(y);
      b.push_back(x);
    }
    bool runrun = true;
    for (int j = 1; j < b.size(); j++) {
      if (b[j - 1] - b[j] == 0 || b[j - 1] - b[j] == 1 | b[j - 1] - b[j] == -1)
        continue;
      runrun = false;
    }
    if (runrun)
      a.push_back(i);
    i++;
  }
  cout << a[K - 1];
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define rept(i, a, b) for (int i = a; i < b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;

bool checklun(ll val) {
  ll prev = val % 10;
  while (val >= 10) {
    val /= 10;
    if (abs(val % 10 - prev) > 1)
      return false;
    prev = val % 10;
  }
  return true;
}

ll nextlun(ll val) {
  if (checklun(val + 1))
    return val + 1;
  for (int i = 1; i < 10; i++) {
    val /= 10;
    val++;
    ll tmp = val % 10;
    if (checklun(val)) {
      rep(j, i) {
        val *= 10;
        tmp = max(tmp - 1, 0LL);
        val += tmp;
      }
      return val;
    } else
      val--;
  }
  return val;
}

int main() {
  ll k;
  in(k);
  vector<ll> dp(100001, 0);
  rep(i, 10) dp[i] = i;
  rept(i, 10, 100001) {
    // out(i << ' ' << nextlun(dp[i-1]));
    dp[i] = nextlun(dp[i - 1]);
  }
  // rept(i, 1, k) cout << dp[i] << ' '; cout << endl;
  out(dp[k]);

  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define rept(i, a, b) for (int i = a; i < b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;

bool checklun(ll val) {
  ll prev = val % 10;
  while (val >= 10) {
    val /= 10;
    if (abs(val % 10 - prev) > 1)
      return false;
    prev = val % 10;
  }
  return true;
}

ll nextlun(ll val) {
  if (checklun(val + 1))
    return val + 1;
  for (int i = 1; i < 10; i++) {
    val /= 10;
    val++;
    ll tmp = val % 10;
    if (checklun(val)) {
      rep(j, i) {
        val *= 10;
        tmp = max(tmp - 1, 0LL);
        val += tmp;
      }
      return val;
    } else
      val--;
  }
  return val;
}

int main() {
  ll k;
  in(k);
  vector<ll> dp(k + 1, 0);
  rep(i, 10) dp[i] = i;
  rept(i, 10, 100001) {
    // out(i << ' ' << nextlun(dp[i-1]));
    dp[i] = nextlun(dp[i - 1]);
  }
  // rept(i, 1, k) cout << dp[i] << ' '; cout << endl;
  out(dp[k]);

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

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

int main() {
  int K, r;
  cin >> K;
  queue<ll> X;
  for (int i = 1; i < 10; i++) {
    X.push(i);
  }
  for (ll i = 1; i < K;) {
    r = X.front() % 10;
    if (r != 0) {
      X.push(X.front() * 10 + r - 1);
    }
    X.push(X.front() * 10 + r);
    if (r != 9) {
      X.push(X.front() * 10 + r + 1);
    }
    X.pop();
    i++;
  }
  cout << X.front() << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

bool judge(ll a) {
  int num;
  for (; a / 10 > 0;) {
    num = a % 10;
    a /= 10;
    if (abs(a % 10 - num) > 1) {
      return false;
    }
  }
  return true;
}

int main() {
  int K;
  ll count = 0, answer;
  cin >> K;
  for (ll i = 1;; i++) {
    if (judge(i) == true) {
      count++;
    }
    if (count == K) {
      answer = i;
      break;
    }
  }
  cout << answer << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define i64 int64_t

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

  queue<i64> lunlunQueue;
  lunlunQueue.push(1);
  lunlunQueue.push(2);
  lunlunQueue.push(3);
  lunlunQueue.push(4);
  lunlunQueue.push(5);
  lunlunQueue.push(6);
  lunlunQueue.push(7);
  lunlunQueue.push(8);
  lunlunQueue.push(9);

  int i;
  i64 num;
  for (i = 0; i < K; i++) {
    num = lunlunQueue.front();
    lunlunQueue.pop();

    if (num % 10 != 0)
      lunlunQueue.push(10 * num + num % 10 - 1);

    lunlunQueue.push(num * 10 + num % 10);

    if (num % 10 != 9)
      lunlunQueue.push(10 * num + num % 10 + 1);
  }

  cout << num;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

#define i64 int64_t

bool Judge(i64 lunlun) {

  int keta1, keta2;

  if (lunlun < 10)
    return true;

  while (lunlun > 10) {
    keta1 = lunlun % 10;
    lunlun /= 10;
    keta2 = lunlun % 10;
    if ((keta1 - keta2 > 1) || (keta2 - keta1 > 1))
      return false;
  }

  return true;
}

int main() {
  int K;
  cin >> K;
  i64 lunlun = 0;

  int i;
  for (i = 0; i < K; i++) {

    /*
    if(!Judge(lunlun+1)){
        while(!Judge(lunlun+1)){
                lunlun+=9;
        }
    }else lunlun++;
    */
    lunlun++;
    while (!Judge(lunlun)) {
      lunlun++;
    }
  }

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

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

int main() {
  long long num = 0, num1 = 0;
  string num1_str = "";
  vector<ll> ans;
  cin >> num;
  queue<ll> que;
  for (ll i = 1; i < 10; i++) {
    que.push(i);
    ans.push_back(i);
  }

  while (!que.empty()) {
    ll v = que.front(); // キューから先頭頂点を取り出す
    que.pop();
    string str = to_string(v);

    if (str[str.size() - 1] != '0') {
      ll tmp;
      ll degit;
      degit = ll(str[str.size() - 1] - '0') - 1;
      string tmp_str = to_string(v);
      tmp_str += to_string(degit);
      tmp = atoll(tmp_str.c_str());
      que.push(tmp);
      ans.push_back(tmp);
    }

    if (1) {
      ll tmp;
      ll degit;
      degit = ll(str[str.size() - 1] - '0');
      string tmp_str = to_string(v);
      tmp_str += (to_string(degit));
      tmp = atoll(tmp_str.c_str());
      que.push(tmp);
      ans.push_back(tmp);
    }

    if (str[str.size() - 1] != '9') {
      ll tmp;
      int degit;
      degit = ll(str[str.size() - 1] - '0') + 1;
      string tmp_str = to_string(v);
      tmp_str += to_string(degit);
      tmp = atoll(tmp_str.c_str());
      que.push(tmp);
      ans.push_back(tmp);
    }
    if (ans.size() > num) {
      break;
    }
  }
  sort(ans.begin(), ans.end());

  cout << ans[num - 1] << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int check_lunlun(string str) {
  int flag = 1;
  if (str.size() > 1) {
    for (int i = 0; i < str.size() - 1; i++) {
      if (abs(str[i] - str[i + 1]) > 1) {
        flag = 0;
        break;
      }
    }
  } else {
    return flag;
  }
  return flag;
}
int main() {
  long long num = 0, num1 = 0;
  string num1_str = "";
  cin >> num;
  while (1) {
    num1++;
    num1_str = to_string(num1);
    if (check_lunlun(num1_str)) {
      num--;
      if (num == 0) {
        break;
      }
    }
  }
  cout << num1 << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define _USE_MATH_DEFINES
#include <functional>
#include <math.h>
using namespace std;

#define rep(i, x) for (ll i = 0; i < x; i++)
#define repn(i, x) for (ll i = 1; i <= x; i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
  if (a > b) {
    return a;
  }
  return b;
}

ll min(ll a, ll b) {
  if (a > b) {
    return b;
  }
  return a;
}

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

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

struct edge {
  ll ind;
  ll fr;
  ll to;
  ll d;
};

///////////////////////////

ll d(ll n) {
  if (n < 10) {
    return 1;
  }
  return d(n / 10) + 1;
}

ll keta(ll n, ll k) {
  if (k == 1) {
    return n % 10;
  } else {
    return keta(n / 10, k - 1);
  }
}

ll p(ll n) {
  if (n == 0) {
    return 1;
  }
  return p(n - 1) * 10;
}

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

  ll ans = 1;
  ll c = 0;

  while (c < X) {
    ll b = 1;
    for (ll i = d(ans) - 1; i >= 1; i--) {
      if (abs(keta(ans, i) - keta(ans, i + 1)) > 1) {
        b = 0;
        ans += p(i - 1);
        break;
      }
    }

    // cout << ans << c << b << endl;

    if (b == 1) {
      c++;
      if (c == X) {
        break;
      }
      ans++;
    }
  }

  cout << ans;

  system("PAUSE");
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define _USE_MATH_DEFINES
#include <functional>
#include <math.h>
using namespace std;

#define rep(i, x) for (ll i = 0; i < x; i++)
#define repn(i, x) for (ll i = 1; i <= x; i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
  if (a > b) {
    return a;
  }
  return b;
}

ll min(ll a, ll b) {
  if (a > b) {
    return b;
  }
  return a;
}

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

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

struct edge {
  ll ind;
  ll fr;
  ll to;
  ll d;
};

///////////////////////////

ll d(ll n) {
  if (n < 10) {
    return 1;
  }
  return d(n / 10) + 1;
}

ll keta(ll n, ll k) {
  if (k == 1) {
    return n % 10;
  } else {
    return keta(n / 10, k - 1);
  }
}

ll p(ll n) {
  if (n == 0) {
    return 1;
  }
  return p(n / 10) * 10;
}

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

  ll ans = 1;
  ll c = 0;

  while (c < X) {
    ll b = 1;
    for (ll i = d(ans) - 1; i >= 1; i--) {
      if (abs(keta(ans, i) - keta(ans, i + 1)) > 1) {
        b = 0;
        ans += p(i - 1);
        break;
      }
    }

    // cout << ans << c << b << endl;

    if (b == 1) {
      c++;
      if (c == X) {
        break;
      }
      ans++;
    }
  }

  cout << ans;

  system("PAUSE");
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#pragma GCC optimize("O3")
using namespace std;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long
#define sp system("pause");
#define MOD 998244353
#define mxN 2005

using namespace std;
set<ll> s;
ll maxx = 400000000;
void solve(ll x) {
  if (s.find(x) != s.end())
    return;
  s.insert(x);
  if (x >= maxx)
    return;

  if (x == 0)
    for (int i = 1; i <= 9; ++i)
      solve(i);
  else {
    ll lst = x % 10;
    if (lst > 0)
      solve(x * 10 + (lst - 1));
    solve(x * 10 + lst);
    if (lst < 9)
      solve(x * 10 + (lst + 1));
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll k;
  cin >> k;
  solve(0);

  while (k) {
    s.erase(s.begin());
    k--;
  }
  cout << *s.begin();

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#pragma GCC optimize("O3")
using namespace std;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long
#define sp system("pause");
#define MOD 998244353
#define mxN 2005

using namespace std;
set<ll> s;
ll maxx = 400000000;
void solve(ll x) {
  if (x >= maxx)
    return;
  if (s.find(x) != s.end())
    return;
  s.insert(x);

  if (x == 0)
    for (int i = 1; i <= 9; ++i)
      solve(i);
  else {
    int lst = x % 10;
    if (lst > 0)
      solve(x * 10 + (lst - 1));
    solve(x * 10 + lst);
    if (lst < 9)
      solve(x * 10 + (lst + 1));
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll k;
  cin >> k;
  solve(0);

  while (k) {
    s.erase(s.begin());
    k--;
  }
  cout << *s.begin();

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

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

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

  queue<int64_t> q;
  for (int64_t i = 1; i <= 9; i++) {
    q.emplace(i);
  }

  for (int64_t i = 0; i < k - 1; i++) {
    int64_t x = q.front();
    q.pop();

    for (int64_t d = max<int64_t>(0, x % 10 - 1);
         d <= min<int64_t>(9, x % 10 + 1); d++) {
      q.emplace(10 * x + d);
    }
  }

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

  return 0;
}

Error: WA

Fixed submission:

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

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

  queue<int64_t> q;
  for (int64_t i = 1; i <= 9; i++) {
    q.emplace(i);
  }

  for (int64_t i = 1; i <= k; i++) {
    int64_t x = q.front();
    q.pop();

    for (int64_t d = max<int64_t>(0, x - 1); d <= min<int64_t>(9, x + 1); d++) {
      q.emplace(10 * x + d);
    }
  }

  cout << q.front() << 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() {
  int k;
  cin >> k;
  vector<ll> 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<ll> old;
    swap(old, a);
    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;
        a.push_back(nx);
      }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int k;
  cin >> k;
  vector<ll> a;

  for (int i = 1; i <= 9; ++i)
    a.push_back(i);
  while (1) {
    if (k <= a.size()) {
      cout << a[k - 1] << endl;
    }
    k -= a.size();
    vector<ll> old;
    swap(old, a);
    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;
        a.push_back(nx);
      }
    }
  }
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
bool lun(string n) {
  int len = n.length();
  for (int i = 1; i < len; i++) {
    if (abs(n[i] - n[i - 1]) > 1)
      return false;
  }
  return true;
}
string nxt(string n) {
  int len = n.length();
  for (int i = len - 2; i >= 0; i--) {
    if (n[i] + 1 != n[i + 1] && n[i + 1] != '9') {
      n[i + 1] += 1;
      for (int j = i + 2; j < len; j++) {
        if (n[j - 1] == '0')
          n[j] = '0';
        else
          n[j] = n[j - 1] - 1;
      }
      return n;
    }
  }
  if (n[0] == '9')
    n = '1' + string(len, '0');
  else {
    n[0]++;
    for (int i = 1; i < len; i++) {
      if (n[i - 1] == '0')
        n[i] = '0';
      else
        n[i] = n[i - 1] - 1;
    }
  }
  return n;
}
int main(void) {
  int k;
  string n = "10";
  cin >> k;
  if (k <= 10) {
    cout << k << endl;
    return 0;
  }
  for (int i = 10; i < k; i++) {
    // cout << n << endl;
    n = nxt(n);
  }
  cout << n << endl;
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
bool lun(string n) {
  int len = n.length();
  for (int i = 1; i < len; i++) {
    if (abs(n[i] - n[i - 1]) > 1)
      return false;
  }
  return true;
}
string nxt(string n) {
  int len = n.length();
  for (int i = len - 2; i >= 0; i--) {
    if (n[i] + 1 != n[i + 1] && n[i + 1] != '9') {
      n[i + 1] += 1;
      for (int j = i + 2; j < len; j++) {
        if (n[j - 1] == '0')
          n[j] = '0';
        else
          n[j] = n[j - 1] - 1;
      }
      return n;
    }
  }
  if (n[0] == '9')
    n = '1' + string(len, '0');
  else {
    n[0]++;
    for (int i = 1; i < len; i++) {
      if (n[i - 1] == '0')
        n[i] = '0';
      else
        n[i] = n[i - 1] - 1;
    }
  }
  return n;
}
int main(void) {
  int k;
  string n = "10";
  cin >> k;
  if (k <= 10)
    return k;
  for (int i = 10; i < k; i++) {
    // cout << n << endl;
    n = nxt(n);
  }
  cout << n << endl;
}