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

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define ll long long
#define MAX 25 * 1e13
#define N 200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A, B) make_pair(A, B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k;
  cin >> k;
  queue<ll> q;
  int cnt = 0;
  for (ll i = 1; i < 10; i++)
    q.push(i);
  while (!q.empty()) {
    ll x = q.front();
    cnt++;
    if (cnt == k) {
      cout << x << endl;
      break;
    }
    q.pop();
    if (x % 10 != 0) {
      q.push(x * 10 + (x % 10) - 1);
    }
    q.push(x * 10 + (x % 10));
    if (x % 10 != 9) {
      q.push(x * 10 + (x % 10) + 1);
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define MAX 25 * 1e13
#define N 200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A, B) make_pair(A, B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;

int ok(ll num) {
  int cu = 0;
  int last = 0;
  last = num % 10;
  num /= 10;
  int flag = 1;
  while (num > 0) {
    cu = num % 10;
    if (abs(cu - last) > 1) {
      flag = 0;
      break;
    }
    last = cu;
    num /= 10;
  }
  if (flag == 0)
    return 0;
  return 1;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll MAXN = 3234566667;

  int k;
  cin >> k;
  int cnt = 0;
  ll y[] = {10000, 20000, 30000, 35000, 40000, 45000, 50000, 55000, 60000,
            65000, 70000, 75000, 80000, 85000, 90000, 95000, 100000};
  ll t[] = {22111101,   76667876,   223221112,  332334565,  434323221,
            543221010,  566545665,  667677888,  888778999,  777656545,
            1012101223, 1211122112, 2101000111, 2212345454, 2323212101,
            3210112121, 3234566667};

  ll be = 0;
  for (int i = 17; i >= 0; i--) {
    if (k >= y[i]) {
      be = t[i];
      cnt = y[i];
      break;
    }
  }

  int flag = 0;
  for (ll i = be + 1; cnt < k && i <= MAXN; i++) {
    if (ok(i)) {
      cnt++;
      if (cnt == k) {
        cout << i << endl;
        flag = 1;
        break;
      }
    }
  }
  if (flag == 0)
    cout << be << endl;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define PI acos(-1)
#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
ll mod = 1e9 + 7;

bool Lunlun(ll x) {
  ll pre = x % 10;
  x /= 10;
  while (x > 0) {
    ll n = x % 10;
    if (abs(pre - n) > 1)
      return false;
    x /= 10;
    pre = n;
  }
  return true;
}

int main() {
  fast_io

      ll k;
  cin >> k;

  queue<ll> que;
  for (int i = 1; i <= 9; i++) {
    que.push(i);
  }
  ll ans;
  rep(i, k) {
    ll x = que.front();
    que.pop();
    if (x % 10 != 0)
      que.push(10 * x + x % 10 - 1);
    que.push(10 * x + x % 10);
    if (x % 10 != 9)
      que.push(10 * x + x % 10 + 1);
    ans = x;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define PI acos(-1)
#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
ll mod = 1e9 + 7;

bool Lunlun(ll x) {
  ll pre = x % 10;
  x /= 10;
  while (x > 0) {
    ll n = x % 10;
    if (abs(pre - n) > 1)
      return false;
    x /= 10;
    pre = n;
  }
  return true;
}

int main() {
  fast_io

      ll k;
  cin >> k;
  ll ans;
  if (k <= 10) {
    cout << k << endl;
    return 0;
  }
  ll cnt = 0;
  ll i = 1;
  while (1) {
    if (Lunlun(i)) {
      cnt++;
    } else {
    }
    if (cnt == k) {
      cout << i << endl;
      return 0;
    }
    i++;
  }
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long k;
  cin >> k;
  queue<long long> q;
  for (int i = 1; i <= 9; i++)
    q.push(i);
  while (!q.empty()) {
    long long x = q.front();
    q.pop();
    k--;
    if (k == 0) {
      cout << x << endl;
      return 0;
    }
    for (int i = x % 10 - 1; i <= x % 10 + 1; i++) {
      if (i < 0 || i >= 10)
        continue;
      q.push(x * 10 + (long long)i);
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
deque<int> ans;
deque<int> func(deque<int> s) {
  int p = s.size() - 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;
    for (int i = 0; i < s.size() - 1; i++) {
      if (abs(s[i] - s[i + 1]) > 1)
        b = i;
    }
    if (s[b + 1] > s[b])
      s[b]++;
    int x = max(s[b] - 1, 0);
    for (int i = b + 1; i < s.size(); i++) {
      s[i] = x;
      x = max(x - 1, 0);
    }
    return s;
  }
}
int main() {

  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    ans = func(ans);
  }
  for (int i : ans)
    cout << i;
  puts("");
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define slowanddetermined                                                      \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define debug(x)                                                               \\
  ;                                                                            \\
  cout << #x << "=" << x << endl;
#define debug2(x, y)                                                           \\
  ;                                                                            \\
  cout << #x << "=" << x << " " << #y << "=" << y << endl;
#define int long long
using namespace std;

int32_t main() {

  int k;
  cin >> k;

  deque<int> dq;
  int cnt = 0;
  for (int i = 1; i <= 9; i++) {
    dq.push_back(i);
  }
  // cout<<"HERE";
  while (true) {
    int fr = dq.front();
    cnt++;
    dq.pop_front();
    if (cnt == k) {
      cout << fr;
      return 0;
    }
    if (fr % 10 != 0) {
      dq.push_back(fr * 10 + (fr % 10) - 1);
    }
    dq.push_back(fr * 10 + fr % 10);
    if (fr % 10 != 9) {
      dq.push_back(fr * 10 + (fr % 10) + 1);
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define slowanddetermined                                                      \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define debug(x)                                                               \\
  ;                                                                            \\
  cout << #x << "=" << x << endl;
#define debug2(x, y)                                                           \\
  ;                                                                            \\
  cout << #x << "=" << x << " " << #y << "=" << y << endl;
#define int long long
using namespace std;

int32_t main() {
  // p_p_m();

  int k;
  cin >> k;

  deque<int> dq;
  int cnt = 0;
  for (int i = 1; i <= 9; i++) {
    dq.push_back(i);
  }
  // cout<<"HERE";
  while (true) {
    int fr = dq.front();
    cnt++;
    dq.pop_front();
    if (cnt == k)
      cout << fr;
    if (fr % 10 != 0) {
      dq.push_back(fr * 10 + (fr % 10) - 1);
    }
    dq.push_back(fr * 10 + fr % 10);
    if (fr % 10 != 9) {
      dq.push_back(fr * 10 + (fr % 10) + 1);
    }
  }

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

//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/04/04.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//  ABC161
//
//

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
// #define __DBG__

void solve(void) {

  ll K;

  cin >> K;

  vector<ll> A[11];
  vector<ll> B;

  if (K < 10) {
    cout << K << endl;
    return;
  }

  REP(i, 9) { A[0].push_back(i + 1); }

  B = A[0];

  REP2(i, 1, 11) {
    for (auto j : A[i - 1]) {
      int d1 = j % 10;
      ll d = j * 10 + d1;
      if (d1 > 0) {
        A[i].push_back(d - 1);
      }
      A[i].push_back(d);
      if (d1 < 9) {
        A[i].push_back(d + 1);
      }
    }
    B.insert(B.end(), ALL(A[i]));
  }
  /*
  for(auto v:B){
    cout << v << " ";
  }
  cout << endl;
  */
  cout << B[K - 1] << endl;

  return;
}

#define TESTCASES 1

int main(int argc, const char *argv[]) {

  cin.tie(0);
  ios::sync_with_stdio(false);

  REP(i, TESTCASES) { solve(); }

  return 0;
}


Error: TLE

Fixed submission:

//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/04/04.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//  ABC161
//
//

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
// #define __DBG__

bool check(ll a) {
  string s = to_string(a);
  bool flag = true;
  REP(i, s.size() - 1) {
    if (abs(s[i] - s[i + 1]) > 1) {
      flag = false;
      break;
    }
  }
  return flag;
}

void solve(void) {

  ll K;

  cin >> K;

  if (K < 10) {
    cout << K << endl;
    return;
  }
  /*
    if(K<36){
      ll count=0;
      REP2(i,1,100){
        if(check(i))count++;
        if(count==K){cout << i << endl;return;}
      }
    }
  */
  ll tmp = 9;

  for (int i = 10; i <= K; i++) {
    tmp++;
    while (!check(tmp)) {
      tmp++;
    }
  }

  cout << tmp << endl;

  return;
}

#define TESTCASES 1

int main(int argc, const char *argv[]) {

  cin.tie(0);
  ios::sync_with_stdio(false);

  REP(i, TESTCASES) { solve(); }

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

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int K;
  cin >> K;
  vector<long long> num = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  while (num.size() < K) {
    long long x = num[0];
    num.erase(num.begin());
    K--;
    long long a = x % 10;
    if (a != 0) {
      num.push_back(10 * x + a - 1);
    }
    num.push_back(10 * x + a);
    if (a != 9) {
      num.push_back(10 * x + a + 1);
    }
  }
  cout << num[K - 1] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

/*string add(string num, int x, int k) {
        for (int i = x; i >= 0; i--) {
                int a = num[i] - '0';
                a += k;
                if (a == 10) {
                        k = 1;
                        num[i] = '0';
                }
                else if (a == -1) {
                        k = -1;
                        num[i] = '9';
                }
                else {
                        k = 0;
                        num[i] = a + '0';
                }
        }
        if (k == 1) {
                num.insert(num.begin(), '1');
        }
        return num;
}*/

int main() {
  int K;
  cin >> K;
  vector<long long> num = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  for (int i = 0; i < K; i++) {
    long long x = num[0];
    if (i == K - 1) {
      cout << x << endl;
      break;
    }
    num.erase(num.begin());
    long long a = x % 10;
    if (a != 0) {
      num.push_back(10 * x + a - 1);
    }
    num.push_back(10 * x + a);
    if (a != 9) {
      num.push_back(10 * x + a + 1);
    }
  }
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int K;
  cin >> K;
  queue<ll> que;
  for (int i = 1; i < 10; i++)
    que.push(i);
  for (int i = 0; i < K - 1; i++) {
    ll s = que.front();
    que.pop();
    for (int j = -1; j <= 1; j++) {
      ll add = (s % 10) + j;
      if (add >= 0 && add <= 9)
        que.push(s * 10 + add);
    }
  }
  cout << que.front() << endl;
  return 0;
}

// K番目に小さいものを求めよという問題でpriority_queueが使える問題は多い．まず，priority_queueに1から9をpushする．以下の操作をK回繰り返す．
// キューの先頭を取り出す．(sとする)
// sの一の位がdであるとき
// d > 0ならキューに10v + (d - 1)をpush
// キューに10v + dをpush
// d < 9ならキューに10v + (d + 1)をpush
// キューにpushされる値は，時系列にそって単調増加であるためpriority_queueではなくqueueでかまわない
// これらの操作はBFSと見なすことが出来る．


Error: WA

Fixed submission:

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int K;
  cin >> K;
  queue<ll> que;
  for (int i = 1; i < 10; i++)
    que.push(i);
  for (int i = 0; i < K - 1; i++) {
    ll s = que.front();
    que.pop();
    for (int j = -1; j <= 1; j++) {
      ll add = (s % 10) + j;
      if (add <= 0 && add >= 9)
        que.push(s * 10 + add);
    }
  }
  cout << que.front() << endl;
  return 0;
}

// K番目に小さいものを求めよという問題でpriority_queueが使える問題は多い．まず，priority_queueに1から9をpushする．以下の操作をK回繰り返す．
// キューの先頭を取り出す．(sとする)
// sの一の位がdであるとき
// d > 0ならキューに10v + (d - 1)をpush
// キューに10v + dをpush
// d < 9ならキューに10v + (d + 1)をpush
// キューにpushされる値は，時系列にそって単調増加であるためpriority_queueではなくqueueでかまわない
// これらの操作はBFSと見なすことが出来る．
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, j, x, y, m, k, t;
  cin >> n;
  m = 0;
  x = 0;
  queue<string> q;
  long long int arr[10 + n];
  k = 0;
  for (i = 1; i <= 9; i++) {
    q.push(to_string(i));
    arr[k++] = i;
  }

  while (1) {
    if (x == 1)
      break;
    long long int size = q.size();
    while (size--) {
      string s1 = q.front();
      q.pop();
      if (s1[s1.length() - 1] != '0') {
        q.push(s1 + to_string(s1[s1.length() - 1] - '0' - 1));
        arr[k++] = stoll(s1 + to_string(s1[s1.length() - 1] - '0' - 1));
        if (k >= n) {
          x = 1;
          break;
        }
      }
      q.push(s1 + to_string(s1[s1.length() - 1] - '0'));
      arr[k++] = stoll(s1 + to_string(s1[s1.length() - 1] - '0'));
      if (k >= n) {
        x = 1;
        break;
      }
      if (s1[s1.length() - 1] != '9') {
        q.push(s1 + to_string(s1[s1.length() - 1] - '0' + 1));
        arr[k++] = stoll(s1 + to_string(s1[s1.length() - 1] - '0' + 1));
        if (k >= n) {
          x = 1;
          break;
        }
      }
    }
  }
  string s2 = "";

  sort(arr, arr + n);
  cout << arr[n - 1] << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, j, x, y, m, k, t;
  cin >> n;
  m = 0;
  x = 0;
  queue<string> q;
  long long int arr[100005];
  k = 0;
  for (i = 1; i <= 9; i++) {
    q.push(to_string(i));
    arr[k++] = i;
  }

  while (1) {
    if (x == 1)
      break;
    long long int size = q.size();
    while (size--) {
      string s1 = q.front();
      q.pop();
      if (s1[s1.length() - 1] != '0') {
        q.push(s1 + to_string(s1[s1.length() - 1] - '0' - 1));
        arr[k++] = stoi(s1 + to_string(s1[s1.length() - 1] - '0' - 1));
        if (k > n) {
          x = 1;
          break;
        }
      }
      q.push(s1 + to_string(s1[s1.length() - 1] - '0'));
      arr[k++] = stoi(s1 + to_string(s1[s1.length() - 1] - '0'));
      if (k > n) {
        x = 1;
        break;
      }
      if (s1[s1.length() - 1] != '9') {
        q.push(s1 + to_string(s1[s1.length() - 1] - '0' + 1));
        arr[k++] = stoi(s1 + to_string(s1[s1.length() - 1] - '0' + 1));
        if (k > n) {
          x = 1;
          break;
        }
      }
    }
  }
  string s2 = "";

  sort(arr, arr + n);
  cout << arr[n - 1] << "\\n";
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  queue<ll> q;
  int k;
  ll lunlun;
  cin >> k;
  for (int i = 1; i < 10; i++)
    q.push(i);
  for (int i = 0; i < k; i++) {
    lunlun = q.front();
    q.pop();
    if (lunlun % 10 != 0)
      q.push(lunlun * 10 + lunlun % 10 - 1);
    q.push(lunlun * 10 + lunlun % 10);
    if (lunlun % 10 != 9)
      q.push(lunlun * 10 + lunlun % 10 + 1);
  }
  cout << lunlun;
}

Error: TLE

Fixed submission:


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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;
  int i = 1;
  int index = 0;
  int tmp = 0;
  int tmp1 = i;
  bool lunlun = true;
  while (true) {
    tmp = i % 10;
    tmp1 = i;
    while (tmp1 >= 10) {
      tmp1 = tmp1 / 10;
      if (abs(tmp - tmp1 % 10) > 1) {
        lunlun = false;
        break;
      } else
        tmp = tmp1 % 10;
    }
    if (lunlun)
      index++;

    if (index == k) {
      cout << i;
      break;
    }
    i++;
    lunlun = true;
  }
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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

ll k;
vector<ll> ans;

void bfs() {
  queue<ll> que;
  rep1(i, 9) que.push(i);
  while (ans.size() < k) {
    ll p = que.front();
    que.pop();
    for (int i = -1; i <= 1; i++) {
      if (p % 10 + i < 0 || p % 10 + i > 9)
        continue;
      ll newNum = p * 10 + p % 10 + i;
      ans.push_back(newNum);
      que.push(newNum);
    }
  }
}

int main() {
  cin >> k;
  rep1(i, 9) ans.push_back(i);
  if (k <= 9) {
    cout << ans[k - 1] << endl;
    return 0;
  }
  bfs();
  // rep(i, k) {
  //   cout << ans[i] << endl;
  // }
  cout << ans[k - 1] << endl;
}

Error: 0

Fixed submission:

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return b / gcd(a, b) * b; }
vector<int> ans;
void dfs(vector<int> v, int keta, int k) {
  if (v.size() == keta) {
    int tmp = pow(10, keta - 1);
    int sum = 0;
    rep(i, keta) {
      // printf("%d%c", v[i], (i==keta-1)?'\\n':' ');
      sum += v[i] * tmp;
      tmp /= 10;
    }
    ans.push_back(sum);
    return;
  }
  int end = v[v.size() - 1];
  for (int i = -1; i <= 1; i++) {
    // this_thread::sleep_for(chrono::seconds(1));
    if (end + i < 0 || end + i > 9)
      continue;
    if (ans[k - 1] != 0)
      return;
    v.push_back(end + i);
    // printf("end: %d push: %d v.size: %d\\n", end, end+i, int(v.size()));
    dfs(v, keta, k);
    v.pop_back();
  }
}

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

  ll k;
  cin >> k;
  int keta = 0;
  ll tmp = k;
  while (tmp > 0) {
    keta++;
    tmp /= 10;
  }

  if (k < 10) {
    cout << k << endl;
    return 0;
  }
  rep1(i, 9) ans.push_back(i);

  rep1(i, keta) { dfs(vector<int>(1, i), keta, k); }
  cout << ans[k - 1] << endl;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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


Error: TLE

Fixed submission:

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

int A[10];

int Lunlunhantei(int a) {
  int i = 0;
  while (1) {
    A[i] = a % 10;
    a = a / 10;
    if (a == 0)
      break;
    i++;
  }
  for (int j = 0; j < i; j++) {
    if (abs(A[j] - A[j + 1]) > 1)
      return 0;
  }
  return 1;
}

int main() {
  int n, count = 0;
  int i = 1;
  cin >> n;
  while (1) {
    if (Lunlunhantei(i)) {
      count++;
      if (count == n)
        break;
    }
    i++;
  }

  cout << i << endl;
}