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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;

int K;
ll A[200000];
ll count1;

int cal(ll keta, ll val, ll f) {
  if (keta == 1) {
    val += f;
    A[count1++] = val;
    return 0;
  } else {
    val += pow(ll(10), keta - 1) * f;
    if (f == 0) {
      cal(keta - 1, val, 0);
      cal(keta - 1, val, 1);
    } else if (f == 9) {
      cal(keta - 1, val, 8);
      cal(keta - 1, val, 9);
    } else {
      cal(keta - 1, val, f - 1);
      cal(keta - 1, val, f);
      cal(keta - 1, val, f + 1);
    }
  }
  return 0;
}

int main(void) {
  cin >> K;
  for (ll i = 1; i < 19; i++) {
    for (ll j = 1; j <= 9; j++) {
      int r = cal(i, 0, j);
      if (K <= count1)
        break;
    }
    if (K <= count1)
      break;
  }
  cout << A[K - 1] << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;

int K;
ll A[100001];
ll count1;

void cal(ll keta, ll val, ll f) {
  if (keta == 1) {
    val += f;
    A[count1++] = val;
    return;
  } else {
    val += pow(ll(10), keta - 1) * f;
    if (f == 0) {
      cal(keta - 1, val, 0);
      cal(keta - 1, val, 1);
    } else if (f == 9) {
      cal(keta - 1, val, 8);
      cal(keta - 1, val, 9);
    } else {
      cal(keta - 1, val, f - 1);
      cal(keta - 1, val, f);
      cal(keta - 1, val, f + 1);
    }
  }
}

int main(void) {
  cin >> K;
  for (ll i = 1; i < 19; i++) {
    for (ll j = 1; j <= 9; j++) {
      cal(i, 0, j);
      if (K <= count1)
        break;
    }
    if (K <= count1)
      break;
  }
  cout << A[K - 1] << endl;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, n) for (long long int i = a; i < n; i++)
#define loop(i, a, n) for (long long int i = a; i >= n; i--)

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

  int a;
  cin >> a;
  vector<string> v(a + 15);
  forr(i, 1, 10) v[i] = to_string(i);
  int k = 1, l = 10;
  while (l <= a) {
    int x = v[k].back() - '0';
    if (x == 0) {
      v[l++] = v[k] + char('0' + x);
      v[l++] = v[k] + char('0' + x + 1);
    } else if (x == 9) {
      v[l++] = v[k] + char('0' + x - 1);
      v[l++] = v[k] + char('0' + x);
    } else {
      v[l++] = v[k] + char('0' + x - 1);
      v[l++] = v[k] + char('0' + x);
      v[l++] = v[k] + char('0' + x + 1);
    }
    if (l > a)
      break;
    k++;
  }
  cout << v[a];

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, n) for (long long int i = a; i < n; i++)
#define loop(i, a, n) for (long long int i = a; i >= n; i--)

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

  int a;
  cin >> a;
  vector<string> v(a + 5);
  forr(i, 0, 9) v[i] = char('0' + i + 1);
  int k = 0, l = 9;
  while (l <= a) {
    int x = v[k].back() - '0';
    if (x == 0) {
      v[l++] = v[k] + char('0' + x);
      v[l++] = v[k] + char('0' + x + 1);
    } else if (x == 9) {
      v[l++] = v[k] + char('0' + x - 1);
      v[l++] = v[k] + char('0' + x);
    } else {
      v[l++] = v[k] + char('0' + x - 1);
      v[l++] = v[k] + char('0' + x);
      v[l++] = v[k] + char('0' + x + 1);
    }
    if (l >= a)
      break;
    k++;
  }
  cout << v[a - 1];

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

// #pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
ll y, k;
set<ll> st = {1, 2, 3, 4, 5, 6, 7, 8, 9};

void solve() {
  priority_queue<ll, vector<ll>, greater<ll>> q;
  for (auto &x : st)
    q.emplace(x);
  while (!q.empty()) {
    if (st.size() >= 1e5)
      return;
    auto x = q.top();
    q.pop();
    y = x * 10 + x % 10;
    if (abs(y % 10 - x % 10) <= 1) {
      if (!st.count(y)) {
        st.insert(y);
        q.push(y);
      }
    }
    y--;
    if (abs(y % 10 - x % 10) <= 1) {
      if (!st.count(y)) {
        st.insert(y);
        q.push(y);
      }
    }
    y += 2;
    if (abs(y % 10 - x % 10) <= 1) {
      if (!st.count(y)) {
        st.insert(y);
        q.push(y);
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  cin >> k;
  vector<ll> v;
  for (auto &x : st)
    v.emplace_back(x);
  cout << v[k - 1] << endl;
  return 0;
}


Error: TLE

Fixed submission:

// #pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e7 + 5;
const int mod = 1e9 + 7;
ll k, s, x, y, sta, f;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> k;
  for (ll i = 1; i <= 3234566667; i++) {
    y = i;
    f = 1;
    sta = y % 10;
    while (y) {
      x = y % 10;
      y = y / 10;
      if (abs(x - sta) > 1) {
        f = 0;
        break;
      }
      sta = x;
    }
    if (f == 1)
      s++;
    if (s == k) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  queue<ll> qq;
  ll K;
  cin >> K;
  ll ans;
  for (int i = 1; i <= 9; i++)
    qq.push(i);
  for (int i = 0; i < K; i++) {
    ll x = qq.front();
    ans = x;
    qq.pop();
    if (x % 10 != 0)
      qq.push(10 * x + x % 10 - 1);
    qq.push(10 * x + x % 10);
    if (x % 10 != 9)
      qq.push(10 * x + x % 10 + 1);
  }
  cout << ans << 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;
typedef pair<int, int> P;

bool ff(ll x) {
  vector<int> A;
  bool ans;
  while (true) {
    int a = x % 10;
    A.push_back(a);
    if ((x / 10) != 0)
      x /= 10;
    else
      break;
  }
  for (int i = 1; i < A.size(); i++) {
    if (0 == abs(A[i] - A[i - 1]) || 1 == abs(A[i] - A[i - 1]))
      ans = true;
    else {
      ans = false;
      break;
    }
  }
  return ans;
}

int main(void) {
  int K;
  cin >> K;
  int count = 10;
  if (K <= 10) {
    cout << K << endl;
    return 0;
  }
  for (ll i = 11; i < 100000000000; i++) {
    if (ff(i)) {
      // cout << i << endl;
      count++;
    }
    if (count == K) {
      cout << i << endl;
      return 0;
    }
  }
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

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

#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

int main() {
  fast_io;

  queue<long long> q;

  long long k;
  cin >> k;

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

  long long x;
  long long a;
  while (!q.empty()) {
    x = q.front();
    q.pop();
    k--;

    if (k == 0) {
      break;
    }

    a = x % 10;

    for (int i = -1; i < 2; i++) {
      if (a + i >= 0 && a + i < 10) {
        // cout<<(x*10)+a+i<<endl;
        q.push((x * 10) + a + i);
      }
    }
  }
  cout << x << endl;
}


Error: 23

Fixed submission:

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

#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

int main() {
  fast_io;

  queue<long long> q;

  long long k;
  cin >> k;

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

  long long x;
  long long a;
  while (!q.empty()) {
    x = q.front();
    q.pop();
    k--;

    if (k == 0) {
      break;
    }

    a = x % 10;

    for (int i = -1; i < 2; i++) {
      if (a + i >= 0 && a + i < 10) {
        // cout<<(x*10)+a+i<<endl;
        q.push((x * 10) + a + i);
      }
    }
  }
  cout << x << endl;

  return x;
}
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++)

using ll = long long;

int main() {
  int k;
  cin >> k;
  vector<ll> a;
  rep(i, 9) a.push_back(i + 1);
  while (1) {
    if (a.size() >= k) {
      cout << a[k - 1] << endl;
      return 0;
    } else {
      k -= a.size();
    }
    vector<ll> prev;
    swap(prev, a);
    for (ll x : prev) {
      for (int d = -1; d <= 1; d++) {
        int nx = x % 10 + d;
        if (nx < 0 || 9 < nx)
          continue;
        a.push_back(10 * x + nx);
      }
    }
  }
}

Error: TLE

Fixed submission:

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

using ll = long long;

int main() {
  int k;
  cin >> k;
  vector<ll> a;
  rep(i, 9) a.push_back(i + 1);
  while (1) {
    if (a.size() >= k) {
      cout << a[k - 1] << endl;
      return 0;
    } else {
      k -= a.size();
    }
    vector<ll> prev;
    swap(prev, a);
    for (int x : prev) {
      for (int d = -1; d <= 1; d++) {
        int nx = x + d;
        if (nx < 0 || 9 < nx)
          continue;
        a.push_back(10 * x + nx);
      }
    }
  }
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdint>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e14, cnt;

ll arr[1000001];
int main() {
  ll n;
  cin >> n;
  queue<long long> q;

  for (ll i = 1; i <= 9; i++)
    q.push(i);
  for (ll i = 1; i <= n; i++) {
    arr[i] = q.front();
    q.pop();
    if (arr[i] % 10 != 0)
      q.push(arr[i] * 10 + arr[i] % 10 - 1);
    q.push(arr[i] * 10 + arr[i] % 10);
    if (arr[i] % 10 != 9)
      q.push(arr[i] * 10 + arr[i] % 10 + 1);
  }
  cout << arr[n];
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdint>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e14, cnt;

ll arr[100001];
int main() {
  ll n;
  cin >> n;
  queue<long long> q;

  for (ll i = 1; i <= 9; i++)
    q.push(i);
  for (ll i = 1; i <= 100001; i++) {
    arr[i] = q.front();
    q.pop();
    if (arr[i] % 10 != 0)
      q.push(arr[i] * 10 + arr[i] % 10 - 1);
    q.push(arr[i] * 10 + arr[i] % 10);
    if (arr[i] % 10 != 9)
      q.push(arr[i] * 10 + arr[i] % 10 + 1);
  }
  cout << arr[n];
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int k;
  cin >> k;
  queue<ll> q;
  for (int i = 1; i < 10; ++i)
    q.push(i);
  rep(i, k - 1) {
    ll n = q.front();
    q.pop();
    for (int j = -1; j <= 1; ++j) {
      int d = n % 10 + j;
      if (d >= 0 && d <= 9)
        q.push(n * 10 + d);
    }
  }
  cout << q.front() << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll k, ans = 0, cnt = 0, num = 10, n = 0;
  cin >> k;
  bool flg = true;

  while (cnt < k) {
    n++;

    num = n;
    flg = true;
    while (num > 10) {
      // cout << num << endl;
      ll t = num % 10;
      ll tt = num % 100 / 10;
      if (abs(tt - t) > 1) {
        flg = false;
        break;
      }
      num /= 10;
    }
    if (flg)
      cnt++;
  }

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

#include <bits/stdc++.h>
#define pb push_back
#define sz(a) long long(a.size())
#define re return
#define all(a) a.begin(), a.end()
using namespace std;
vector<long long> ans[17];
signed main() {
  long long x;
  cin >> x;
  for (long long i = 1; i <= 9; i++) {
    ans[0].pb(i);
  }
  for (int i = 0; i < 10; i++) {
    for (auto j : ans[i]) {
      for (long long k = max((long long)(0), (long long)(j % 10 - 1));
           k <= min((long long)(9), (long long)(j % 10 + 1)); k++) {
        ans[i + 1].pb(10 * j + k);
      }
    }
  }
  for (long long i = 0; i <= 10; i++) {
    if (x > ans[i].size())
      x -= ans[i].size();
    else {
      cout << ans[i][x - 1];
      break;
    }
  }
  re 0; // D题
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define sz(a) long long(a.size())
#define re return
#define all(a) a.begin(), a.end()
using namespace std;
vector<long long> ans[17];
signed main() {
  long long x;
  cin >> x;
  for (long long i = 1; i <= 9; i++) {
    ans[0].pb(i);
  }
  for (int i = 0; i < 15; i++) {
    for (auto j : ans[i]) {
      for (long long k = max((long long)(0), (long long)(j % 10 - 1));
           k <= min((long long)(9), (long long)(j % 10 + 1)); k++) {
        ans[i + 1].pb(10 * j + k);
      }
    }
  }
  for (long long i = 0; i <= 15; i++) {
    if (x > ans[i].size())
      x -= ans[i].size();
    else {
      cout << ans[i][x - 1];
      break;
    }
  }
  re 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"

using namespace std;
#define all(a) (a).begin(), (a).end()
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

vector<long long> v;
void rekkyo(int i, int last) {
  if (last != 0) {
    int h = stol(to_string(i) + to_string(last - 1));
    if (h <= 323456666)
      rekkyo(h, last - 1);
    v.push_back(h);
  }
  int j = stol(to_string(i) + to_string(last));
  if (j <= 323456666)
    rekkyo(j, last);
  v.push_back(j);
  if (last != 9) {
    int k = stol(to_string(i) + to_string(last + 1));
    if (k <= 323456666)
      rekkyo(k, last + 1);
    v.push_back(k);
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long K;
  cin >> K;
  FOR(i, 1, 10) {
    v.push_back(i);
    rekkyo(i, i);
  }
  sort(all(v));
  cout << v[K - 1] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"

using namespace std;
#define all(a) (a).begin(), (a).end()
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

vector<int> v;
void rekkyo(int i, int last) {
  if (last != 0) {
    int h = stol(to_string(i) + to_string(last - 1));
    v.push_back(h);
    if (h <= 323456666)
      rekkyo(i, last - 1);
    else
      return;
  }
  int j = stol(to_string(i) + to_string(last));
  v.push_back(j);
  if (j <= 323456666)
    rekkyo(j, last);
  else
    return;
  if (last != 9) {
    int k = stol(to_string(i) + to_string(last + 1));
    v.push_back(k);
    if (k <= 323456666)
      rekkyo(k, last);
    else
      return;
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long K;
  cin >> K;
  FOR(i, 1, 10) {
    v.push_back(i);
    rekkyo(i, i);
  }
  sort(all(v));
  cout << v[K - 1] << endl;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long LL;

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

  vector<vector<int>> count(10, vector<int>());
  REP(i, 10) { count[i].push_back(i % 3 == 0 ? 1 : 0); }
  for (int i = 0; i <= 18; ++i) {
    count[0].push_back(count[0][i] + count[1][i]);
    count[9].push_back(count[8][i] + count[9][i]);
    for (int j = 1; j <= 8; ++j) {
      count[j].push_back(count[j - 1][i] + count[j][i] + count[j + 1][i]);
    }
  }
  LL ret = 0;
  for (int keta = 1; keta <= 18; ++keta) {
    for (int n = 1; n <= 9; ++n) {
      if (count[n][keta] < K) {
        K -= count[n][keta];
      } else {
        ret = n;
        while (--keta > 0) {
          if (n >= 1 && K <= count[n - 1][keta]) {
            --n;
          } else {
            if (n >= 1) {
              K -= count[n - 1][keta];
            }
            if (K > count[n][keta]) {
              K -= count[n][keta];
              ++n;
            }
          }
          ret = ret * 10 + n;
        }
        cout << ret << endl;
        return 0;
      }
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long LL;

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

  vector<vector<int>> count(10, vector<int>());
  REP(i, 10) { count[i].push_back(i % 3 == 0 ? 1 : 0); }
  for (int i = 0; i <= 18; ++i) {
    count[0].push_back(count[0][i] + count[1][i]);
    count[9].push_back(count[8][i] + count[9][i]);
    for (int j = 1; j <= 8; ++j) {
      count[j].push_back(count[j - 1][i] + count[j][i] + count[j + 1][i]);
    }
  }
  LL ret = 0;
  for (int keta = 1; keta <= 18; ++keta) {
    for (int n = 1; n <= 9; ++n) {
      if (count[n][keta] < K) {
        K -= count[n][keta];
      } else {
        ret = n;
        while (--keta > 0) {
          if (n >= 1 && K <= count[n - 1][keta]) {
            --n;
          } else {
            K -= count[n - 1][keta];
            if (K > count[n][keta]) {
              K -= count[n][keta];
              ++n;
            }
          }
          ret = ret * 10 + n;
        }
        cout << ret << endl;
        return 0;
      }
    }
  }
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <queue>
#include <stdio.h>
#define absi(n) (n > 0 ? (n) : -(n))
typedef long long ll;
bool lunlun(ll);
std::queue<ll> qll;
int main() {
  ll K, i, j;
  scanf("%lld", &K);
  for (i = 1; i < 10; i++) {
    qll.push(i);
  }
  for (j = 0; j < K; j++) {
    i = qll.front();
    qll.pop();
    if (i % 10 != 0) {
      qll.push(i * 10 + i % 10 - 1);
    }
    qll.push(i * 10 + i % 10);
    if (i % 10 != 9) {
      qll.push(i * 10 + i % 10 + 1);
    }
  }
  printf("%lld", i);

  // for(i=1;;){
  //   if(lunlun(i)){
  //     j++;
  //     if(j == K){
  //       printf("%lld",i);
  //       return 0;
  //     }
  //   }
  // }
}

bool lunlun(ll X) {
  int d, od;
  od = X % 10;
  X = X / 10;
  while (X != 0) {
    d = X % 10;
    if (absi(d - od) > 1) {
      return false;
    }
    od = d;
    X = X / 10;
  }
  return true;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#define absi(n) (n > 0 ? (n) : -(n))
bool lunlun(int);
int main() {
  int K, i, j;
  scanf("%d", &K);
  for (j = 0, i = 1;; i++) {
    if (lunlun(i)) {
      j++;
      if (j == K) {
        printf("%d", i);
        return 0;
      }
    }
  }
}

bool lunlun(int X) {
  int d, od;
  od = X % 10;
  X = X / 10;
  while (X != 0) {
    d = X % 10;
    if (absi(d - od) > 1) {
      return false;
    }
    od = d;
    X = X / 10;
  }
  return true;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
#define MAXN 1000100
#define ll long long
int n, a[MAXN], head, t;
int main() {
  scanf("%d", &n);
  head = 1;
  for (int i = 1; i <= n; i++) {
    a[1]++;
    t = 0;
    for (int j = 1; j <= head - 1; j++) {
      if (a[j] > a[j + 1] + 1 || a[j] == 10)
        t = j, a[j + 1]++;
      else
        break;
    }
    if (a[head] == 10) {
      t = head;
      a[++head] = 1;
    }
    for (int j = t; j >= 1; j--)
      a[j] = max(0, a[j + 1] - 1);
    //	for(int i=head;i>=1;i--) printf("%d",a[i]);
    //	cout<<endl;
  }
  for (int i = head; i >= 1; i--)
    printf("%d", a[i]);
  cout << endl; // cout<<t<<endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
#define MAXN 1000100
#define ll long long
ll n, m, a[MAXN], d[10], len, ans;
bool check(ll u) {
  len = 0;
  while (u) {
    d[++len] = u % 10;
    u /= 10;
  }
  for (ll i = 1; i <= len - 1; i++)
    if (abs(d[i] - d[i + 1]) > 1)
      return false;
  return true;
}
int main() {
  scanf("%lld", &n);
  for (ll i = 1; i <= 1000000000; i++) {
    if (check(i) == true) {
      n--;
      if (n == 0) {
        printf("%d\\n", i);
        return 0;
      }
    }
  }
  cout << ans << endl;

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

#include <bits/stdc++.h>
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define prev fhsgfhjf
#define plus fsghsf
#define minus ytryr

using namespace std;

inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

deque<int> next_good(deque<int> s) {
  int p = sz(s) - 1;
  while (p >= 0 && s[p] == 9) {
    s[p] = 0;
    p--;
  }
  if (p == -1) {
    s.push_front(1);
  } else {
    s[p]++;
  }
  while (true) {
    int b = -1;
    rep(i, 0, sz(s) - 1) {
      if (abs(s[i] - s[i + 1]) > 1) {
        b = i;
        break;
      }
    }
    if (b == -1) {
      break;
    }
    if (s[b + 1] > s[b]) {
      s[b]++;
    }
    int lll = max(s[b] - 1, 0);
    rep(i, b + 1, sz(s)) {
      s[i] = lll;
      lll = max(lll - 1, 0);
    }
  }
  return s;
}

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;

  int k;
  cin >> k;
  deque<int> ans = {0};
  rep(i, 0, k) { ans = next_good(ans); }
  for (int i : ans) {
    cout << i;
  }
  cout << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

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

int k;
int num = 0;

bool check(long long kr) {
  char kx[15];
  sprintf(kx, "%lld", kr);
  int i = 0, j = 0;
  for (i = 0; i < strlen(kx) - 1; i++) {
    j = i + 1;
    if (abs(kx[i] - kx[j]) > 1)
      return false;
  }
  return true;
}

long long find() {
  long long i = 1;
  while (num < k) {
    if (check(i))
      num++;
    i++;
  }
  return i - 1;
}

int main() {
  scanf("%d", &k);
  printf("%lld\\n", find());
  return 0;
}