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

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e6 + 10;

LL dp[10][12], k, num[12], cnt = 0, pos;

void dfs(int ind, int l) {
  if (ind > pos)
    return;
  if (ind == 1) {
    for (int i = 1; i <= 9; i++) {
      if (k > dp[i][pos - ind + 1]) {
        k -= dp[i][pos - ind + 1];
      } else {
        cout << i;
        dfs(ind + 1, i);
        break;
      }
    }
  } else {
    for (int i = l - 1; i <= l + 1; i++) {
      if (i < 0 || i > 9)
        continue;
      if (k > dp[i][pos - ind + 1]) {
        k -= dp[i][pos - ind + 1];
      } else {
        cout << i;
        dfs(ind + 1, i);
        break;
      }
    }
  }
}

int main() {
  /*
  dp[i][j]= dp[i-1 i i+1 ][ j-1 ]
  dp[1~9][j] sum > K
  dp[2][2]>=K
  len=2
  dp[k][1]=1
  */
  cin >> k;
  for (int i = 0; i <= 9; i++)
    dp[i][1] = 1;
  for (int j = 2; j <= 10; j++) {
    for (int i = 0; i <= 9; i++) {
      if (i == 0)
        dp[i][j] = dp[i][j - 1] + dp[i + 1][j - 1];
      else if (i == 9)
        dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1];
      else
        dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1] + dp[i + 1][j - 1];
      // if (j<=2)
      // cout<<"i:"<<i<<" "<<dp[i][j]<<" ";
    }
    // cout<<endl;
  }
  for (int i = 1; i <= 10; i++) {
    LL sum = 0;
    for (int j = 1; j <= 9; j++)
      sum += dp[j][i];
    if (k > sum) {
      k -= sum;
    } else {
      pos = i;
      break;
    }
  }
  dfs(1, 0);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e6 + 10;

LL getStart(LL x, LL b) {
  LL t = x / b;
  LL s = 0;
  while (b) {
    s = s * 10 + t;
    b /= 10;
    if (t - 1 >= 0)
      t--;
  }
  return s;
}

LL getEnd(LL x, LL b) {
  LL t = x / b;
  LL s = 0;
  while (b) {
    s = s * 10 + t;
    b /= 10;
    if (t + 1 <= 9)
      t++;
  }
  return s;
}

LL ok(LL x) {
  LL l = x % 10;
  x /= 10;
  while (x) {
    LL f = abs(x % 10 - l);
    if (f > 1)
      return 0;
    l = x % 10;
    x /= 10;
  }
  return 1;
}

int main() {
  // printf("%lld %lld\\n",getStart(10000,10000),getEnd(10000,10000));
  // printf("%d\\n",ok(12010));
  LL k;
  cin >> k;
  if (k < 10) {
    cout << k << endl;
  } else {
    k -= 9;
    LL cnt = 0;
    for (LL i = 10;; i *= 10) {
      for (LL k = i; k <= 9 * i; k += i) {
        LL s = getStart(k, i), e = getEnd(k, i);
        for (LL j = s; j <= e; j++) {
          if (ok(j))
            cnt++;
          if (cnt == k) {
            cout << j << endl;
            return 0;
          }
        }
      }
    }
    /*
    1 2 3 4 5 6 7 8 9
    10 11 12   21 22 23   87 88 89    98 99
    1234
    1 012
    0 1
    1 012
    2 123
    */
  }
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define INF 1e15
#define NASH 1e9 + 7
#define MAXN 200005
using namespace std;
ll n, k, a[1000];
int main() {
  cin >> k;
  for (int i = 0; i <= 20; i++)
    a[i] = -1;
  a[0] = 0;
  while (k--) {
    a[0]++;
    for (int i = 0; i < 20; i++) {
      if (a[i] > 9) {
        a[i + 1] = max(1LL, a[i + 1] + 1LL);
        a[i] = max(0LL, a[i + 1] - 1);
        continue;
      }
      if (a[i + 1] != -1 && abs(a[i] - a[i + 1]) > 1) {
        a[i + 1]++;
        a[i] = max(0LL, a[i + 1] - 1);
        continue;
      }
      for (int j = i - 1; j >= 0; j--) {
        a[j] = max(0LL, a[j + 1] - 1);
      }
      break;
    }
    // if (1){
    //     for (int i=19; i>=0; i--){
    //         if (a[i]==-1) continue;
    //         cout<<a[i];
    //     } cout<<endl;
    // }
  }
  for (int i = 19; i >= 0; i--) {
    if (a[i] == -1)
      continue;
    cout << a[i];
  }
}
/*
 */

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define INF 1e15
#define NASH 1e9 + 7
#define MAXN 200005
using namespace std;
ll n, k, a[20];
int main() {
  cin >> k;
  for (int i = 0; i <= 20; i++)
    a[i] = -1;
  a[0] = 0;
  while (k--) {
    a[0]++;
    for (int i = 0; i < 20; i++) {
      if (a[i] > 9) {
        a[i] = 0;
        a[i + 1] = max(1LL, a[i + 1] + 1LL);
        continue;
      }
      if (a[i + 1] == -1)
        break;
      if (abs(a[i] - a[i + 1]) > 1) {
        a[i + 1]++;
        a[i] = max(0LL, a[i + 1] - 1);
      }
    }
  }
  for (int i = 19; i >= 0; i--) {
    if (a[i] == -1)
      continue;
    cout << a[i];
  }
}
/*
 */
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#define il inline
#define re register
#define fo(i, j, k) for (register int i = j; i <= k; i++)
#define inf 0x7fffffff
typedef long long ll;
using namespace std;
il ll read() {
  re ll x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return f * x;
}
queue<ll> q;
int main() {
  int k = read();
  fo(i, 1, 9) q.push(i);
  fo(i, 1, k) {
    ll x = q.front();
    q.pop();
    int y = x % 10;
    if (y != 0)
      q.push(x * 10 + y - 1);
    q.push(x * 10 + y);
    if (y != 9)
      q.push(x * 10 + y + 1);
    if (i == k) {
      printf("%lld\\n", x);
      return 0;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#define il inline
#define re register
#define fo(i, j, k) for (register int i = j; i <= k; i++)
#define inf 0x7fffffff
typedef long long ll;
using namespace std;
il ll read() {
  re ll x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return f * x;
}
int n, k, c, cnt, pre;
string s;
int dp1[200010], dp2[200010], ans[200010];
int main() {
  n = read(), k = read(), c = read();
  cin >> s;
  s = " " + s;
  pre = -c - 1;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'x')
      dp1[i] = dp1[i - 1];
    else {
      if (pre + c + 1 <= i) {
        dp1[i] = dp1[i - 1] + 1;
        pre = i;
      } else
        dp1[i] = dp1[i - 1];
    }
  }
  pre = n + c + 1;
  for (int i = n; i >= 1; i--) {
    if (s[i] == 'x')
      dp2[i] = dp2[i + 1];
    else {
      if (pre - c - 1 >= i) {
        dp2[i] = dp2[i + 1] + 1;
        pre = i;
      } else
        dp2[i] = dp2[i + 1];
    }
  }
  //	fo(i,1,n) printf("%d %d\\n",dp1[i],dp2[i]);
  fo(i, 1, n) {
    if (dp1[i - 1] + dp2[i + 1] == k - 1 && s[i] == 'o') {
      ans[++cnt] = i;
    }
  }
  fo(i, 1, cnt) printf("%d\\n", ans[i]);
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;
const int inf = 1001001001;
vector<ll> ans;
ll absc(ll a, ll b) { return (a - b > 0 ? a - b : b - a); }
ll mini(ll a, ll b) { return (a > b ? b : a); }
int keta(ll a, int ketame) {
  rep(i, ketame - 1) a /= 10;
  if (a)
    return a % 10;
  else
    return -1;
}
void ume(ll i) {
  if (i / 3234566668)
    return;
  ans.push_back(i);
  if (i % 10 == 0) {
    if (i)
      ume(i * 10 + 0);
    if (i)
      ume(i * 10 + 1);
  } else if (i % 10 == 9) {
    ume(i * 10 + 8);
    ume(i * 10 + 9);
  } else {
    ume(i * 10 + (i % 10) + 1);
    ume(i * 10 + (i % 10));
    ume(i * 10 + (i % 10) - 1);
  }
}
int main() {
  ll k;
  ;
  string a[100010] = {};
  cin >> k;
  for (int i = 0; i < 10; i++) {
    ume(i);
  }
  sort(ans.begin(), ans.end());
  cout << ans[k];
}


Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;
const int inf = 1001001001;
vector<ll> ans;
ll absc(ll a, ll b) { return (a - b > 0 ? a - b : b - a); }
ll mini(ll a, ll b) { return (a > b ? b : a); }
int keta(ll a, int ketame) {
  rep(i, ketame - 1) a /= 10;
  if (a)
    return a % 10;
  else
    return -1;
}
void ume(int i) {
  if (i / 3234566667)
    return;
  ans.push_back(i);
  if (i % 10 == 0) {
    ume(i * 10 + 0);
    ume(i * 10 + 1);
  } else if (i % 10 == 9) {
    ume(i * 10 + 8);
    ume(i * 10 + 9);
  } else {
    ume(i * 10 + (i % 10) + 1);
    ume(i * 10 + (i % 10));
    ume(i * 10 + (i % 10) - 1);
  }
}
int main() {
  ll k;
  ;
  string a[100010] = {};
  cin >> k;
  for (int i = 0; i < 10; i++) {
    ume(i);
  }
  sort(ans.begin(), ans.end());
  cout << a[k + 9];
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

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

#define pb push_back
#define sf(x) scanf("%d", &x)
#define sfl(x) scanf("%lld", &x)
#define pf(x) printf("%d\\n", x)
#define pfl(x) printf("%lld\\n", x)
#define endl '\\n'
#define pii pair<int, int>
#define mapii map<int, int>
#define mapll map<ll, ll>
#define mapci map<char, int>
#define mapcl map<char, ll>
#define mapsi map<string, int>
#define mapsl map<string, ll>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vd vector<double, double>
#define all(c) c.begin(), c.end()
#define F first
#define S second
#define mp make_pair
#define ftc(x) cerr << #x << ": " << x << " " << endl;
#define PI acos(-1)
#define lcm(a, b) ((a * b) / __gcd(a, b))
// int dx[] = {0,1,0,-1};
// int dy[] = {-1,0,1,0};

//   cout<<std::setprecision(12)<<
vl v;
bool ok(ll x) {
  ll prv = x % 10, l;
  while (x) {
    l = (x % 10);
    if (abs(prv - l) > 1)
      return false;
    prv = x % 10;
    x /= 10;
  }
  return true;
}
void pre(ll x) {
  if (x >= 4234566668)
    return;
  v.pb(x);
  ll m = x % 10;
  if (m == 9) {
    pre((x * 10) + m);
    pre((x * 10) + 8);
  } else if (m == 0) {
    pre((x * 10));
    pre((x * 10) + 1);
  } else {
    pre((x * 10) + m);
    pre((x * 10) + (m + 1));
    pre((x * 10) + (m - 1));
  }
}
int main() {

  ll a, i, j, k, l, m, n, ta;

  for (i = 1; i <= 9; i++)
    pre(i);
  sort(all(v));
  unique(all(v));
  v.resize(distance(all(v)));

  cin >> a;
  cout << v[a - 1] << endl;
}


Error: 0

Fixed submission:

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

#define pb push_back
#define sf(x) scanf("%d", &x)
#define sfl(x) scanf("%lld", &x)
#define pf(x) printf("%d\\n", x)
#define pfl(x) printf("%lld\\n", x)
#define endl '\\n'
#define pii pair<int, int>
#define mapii map<int, int>
#define mapll map<ll, ll>
#define mapci map<char, int>
#define mapcl map<char, ll>
#define mapsi map<string, int>
#define mapsl map<string, ll>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vd vector<double, double>
#define all(c) c.begin(), c.end()
#define F first
#define S second
#define mp make_pair
#define ftc(x) cerr << #x << ": " << x << " " << endl;
#define PI acos(-1)
#define lcm(a, b) ((a * b) / __gcd(a, b))
// int dx[] = {0,1,0,-1};
// int dy[] = {-1,0,1,0};

//   cout<<std::setprecision(12)<<
vl v;

void pre(ll x) {
  if (x >= 100000000)
    return;
  v.pb(x);
  ll m = x % 10;
  m = (x * 10) + m;
  pre(m);
  pre(m - 1);
  pre(m + 1);
}
int main() {

  ll a, i, j, k, l, m, n, ta;

  for (i = 1; i <= 8; i++)
    pre(i);
  v.pb(9);
  sort(all(v));

  cin >> a;
  cout << v[a - 1] << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long
queue<ll> q;

int main() {
  int k;
  cin >> k;
  for (int i = 1; i <= 9; i++)
    q.push(i);

  int j = 1;

  while (j < k) {
    ll p = q.front();
    q.pop();
    j++;

    ll u = p % 10;

    if (u != 0)
      q.push(p * 10 + u - 1);

    q.push(p * 10 + u);

    if (u != 9)
      q.push(p * 10 + u + 1);
  }
  cout << q.front() << endl;
}


Error: TLE

Fixed submission:

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

void lunlun() {
  ll i, j, res, c = 0;

  for (i = 1; i <= 12; i++)
    lun.push_back(i);
  for (i = 13; i <= 1000000; i++) {
    res = i;
    c = 0;
    while (res > 9) {
      ll a, b;
      a = res % 10;
      res /= 10;

      b = res % 10;
      // res/=10;
      if (abs(a - b) > 1) {
        c = 1;
        break;
      }
    }
    if (c == 0)
      lun.push_back(i);
  }
}
void lunlun2() {
  ll i, j, res, c;
  for (i = 1000001; i <= 3234566667; i++) {
    res = i;
    c = 0;
    while (res > 9) {
      ll a, b;
      a = res % 10;
      res /= 10;

      b = res % 10;
      // res/=10;
      if (abs(a - b) > 1) {
        c = 1;
        break;
      }
    }
    if (c == 0)
      lun.push_back(i);
  }
}
int main() {
  lunlun();
  lunlun2();
  int n;
  cin >> n;
  cout << lun[n - 1] << endl;
}
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 < N; i++)
typedef long long ll;
#define dump(x) cerr << #x << "=" << x << endl
using P = pair<int, int>;

bool ok(ll n) {
  ll tmp = n;
  if (n <= 10) {
    return true;
  }

  while (tmp != 0) {
    ll tmp3 = tmp % 10;
    tmp /= 10;
    if (tmp == 0) {
      return true;
    }
    ll tmp2 = tmp % 10;
    if (abs(tmp3 - tmp2) <= 1) {
      continue;
    } else {
      return false;
    }
  }

  return true;
}

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

  int cnt = 0;
  ll tmp;
  while (cnt != k) {
    tmp = q.front();
    q.pop();
    if (tmp % 10 != 0) {
      q.push(tmp * 10 + (tmp % 10 - 1));
    }
    q.push(tmp * 10 + tmp % 10);

    if (tmp % 10 != 9) {
      q.push(tmp * 10 + (tmp % 10 + 1));
    }

    cnt++;
  }

  cout << tmp << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

bool ok(ll n) {
  ll tmp = n;
  if (n <= 10) {
    return true;
  }

  while (tmp != 0) {
    ll tmp3 = tmp % 10;
    tmp /= 10;
    if (tmp == 0) {
      return true;
    }
    ll tmp2 = tmp % 10;
    if (abs(tmp3 - tmp2) <= 1) {
      continue;
    } else {
      return false;
    }
  }

  return true;
}

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

  if (k <= 12) {
    cout << k << endl;
    return 0;
  }

  int cnt = 0;
  for (ll i = 1; i < 3234566668; i++) {
    if (ok(i))
      cnt++;

    if (cnt == k) {
      cout << i << endl;
      return 0;
    }
  }

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

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

int main(int argc, char **argv) {
  unsigned int k;
  cin >> k;

  vector<long long> a;
  for (int i = 1; i < 10; ++i)
    a.push_back(i);

  while (true) {
    if (k <= a.size()) {
      std::cout << a[k - 1] << std::endl;
      return 0;
    }
    k -= a.size();

    vector<long long> old;
    swap(old, a);
    for (long long x : old) {
      int last = x % 10;
      for (int i = -1; i <= 1; ++i) {
        int dx = last + i;
        if (dx < 0 || 9 < dx)
          continue;
        else {
          long long nx = x * 10 + dx;
          a.push_back(nx);
        }
      }
    }
  }
}


Error: TLE

Fixed submission:

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

vector<long long> num2digit(long long num) {
  vector<long long> v;

  while (true) {
    long long a = num % 10;
    v.push_back(a);
    num /= 10;
    if (num == 0)
      break;
  }
  return v;
}

int main(int argc, char **argv) {
  long long k;
  cin >> k;

  long long num = 1;
  long long i = 1;
  while (true) {
    vector<long long> v = num2digit(num);

    bool flag = true;
    long long digit = v[0];
    for (size_t j = 1; j < v.size(); ++j) {
      long long ab = abs(digit - v[j]);
      if (ab > 1) {
        flag = false;
        break;
      } else {
        digit = v[j];
      }
    }

    if (flag) {
      if (i == k)
        break;
      ++i;
    }
    ++num;
  }

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

#include <bits/stdc++.h>
#define int long long
using namespace std;
queue<int> q;
int a, n, k, cnt;
signed main() {
  scanf("%lld", &n);
  for (int i = 1; i <= 9; i++)
    q.push(i);
  n--;
  while (n--) {
    int f = q.front();
    q.pop();
    a = f % 10;
    if (a != 0)
      q.push(f * 10 + a - 1);
    q.push(f * 10 + a);
    if (a != 9)
      q.push(f * 10 + a + 1);
  }
  printf("%lld", q.front());
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long
using namespace std;
queue<int> q;
int a, n, k, cnt;
signed main() {
  cin >> n;
  if (n <= 9)
    cout << n;
  for (int i = 1; i <= 9; i++)
    q.push(i);
  cnt = 9;
  while (cnt != n) {
    int f = q.front();
    q.pop();
    a = f % 10;
    if (a != 0) {
      cnt++;
      if (cnt == n) {
        cout << f * 10 + a - 1;
        return 0;
      } else
        q.push(f * 10 + a - 1);
    }
    cnt++;
    if (cnt == n) {
      cout << f * 10 + a;
      return 0;
    } else
      q.push(f * 10 + a);
    if (a != 9) {
      cnt++;
      if (cnt == n) {
        cout << f * 10 + a + 1;
        return 0;
      } else
        q.push(f * 10 + a + 1);
    }
  }
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <typename T, typename cmp=less<T>> using oset =tree<T, null_type,
// cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define inf 100000000000000000
#define ll long long
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define test                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
void mahakal() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
}
int main() {
  // mahakal(),fast;

  ll n;
  cin >> n;
  queue<ll> q;
  for (ll i = 1; i <= 9; i++)
    q.push(i);
  while (n > 1) {
    ll ps = q.front();
    q.pop();
    // cerr<<ps<<" ";
    if (ps % 10 != 0)
      q.push(10 * ps + ps % 10 - 1);
    q.push(10 * ps + ps % 10);
    if (ps % 10 != 9)
      q.push(10 * ps + ps % 10 + 1);
    n--;
  }
  cout << q.front() << endl;
  return 0;
}

Error: -6

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <typename T, typename cmp=less<T>> using oset =tree<T, null_type,
// cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define inf 100000000000000000
#define ll long long
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define test                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
void mahakal() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
}
int main() {
  mahakal(), fast;

  ll n;
  cin >> n;
  queue<ll> q;
  for (ll i = 1; i <= 9; i++)
    q.push(i);
  while (n > 1) {
    ll ps = q.front();
    q.pop();
    // cerr<<ps<<" ";
    if (ps % 10 != 0)
      q.push(10 * ps + ps % 10 - 1);
    q.push(10 * ps + ps % 10);
    if (ps % 10 != 9)
      q.push(10 * ps + ps % 10 + 1);
    n--;
  }
  cout << q.front() << endl;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rp(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
ll dp[10][10];
int main() {
  rp(i, 10) dp[i][0] = 1;
  for (int j = 1; j < 10; j++) {
    rp(i, 10) {
      if (i == 0) {
        dp[i][j] = dp[0][j - 1] + dp[1][j - 1];
      } else if (i == 9) {
        dp[i][j] = dp[8][j - 1] + dp[9][j - 1];
      } else {
        dp[i][j] = dp[i + 1][j - 1] + dp[i][j - 1] + dp[i - 1][j - 1];
      }
    }
  }
  // cout<< dp[2][3] << endl;
  ll k;
  cin >> k;
  ll sum = 0;
  bool ok = false;
  ll i0, j0;
  for (int i = 0; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      if (sum + dp[j][i] < k) {
        sum += dp[j][i];
        // cout << j << i <<" " << sum<< endl;
      } else {
        ok = true;
        j0 = j;
        i0 = i;
        break;
      }
    }
    if (ok)
      break;
  }
  // cout << j0 << endl;
  // cout << i0 << endl;
  k -= sum;
  // cout << k << endl;
  sum = 0;
  ll ans = j0;
  for (ll i = i0 - 1; i >= 0; i--) {
    // cout << "here2" << endl;
    for (ll j = max(j0 - 1, (ll)0); j <= min(j0 + 1, (ll)10); j++) {
      // cout<<j<<endl;
      if (sum + dp[j][i] < k)
        sum += dp[j][i];
      else {
        // cout << "here" << endl;
        ans = ans * 10 + j;
        j0 = j;
        k -= sum;
        sum = 0;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

bool lunlun(deque<int> v) {
  int n = v.size();
  if (n == 1)
    return true;
  bool ok = true;
  rp(i, n - 1) {
    if (v.at(i) - v.at(i + 1) > 1 || v.at(i + 1) - v.at(i) > 1) {
      ok = false;
      break;
    }
  }
  return ok;
}

int main() {
  ll count = 0;
  ll x = 1;
  ll k;
  cin >> k;
  while (1) {
    deque<int> xs;
    ll xi = x;
    while (xi) {
      xs.push_back(xi % 10);
      xi /= 10;
    }
    if (lunlun(xs))
      count++;
    if (count == k)
      break;
    x++;
  }
  cout << x << endl;
  return 0;
}