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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)

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

  vector<ll> lun(max(11, K + 3));

  rep1(i, 10) { lun[i] = i; }

  int i = 1, j = 10;
  while (j <= K) {
    int r = lun[i] % 10;
    ll x10 = lun[i] * 10;
    if (r != 0)
      lun[j++] = x10 + r - 1;
    lun[j++] = x10 + r;
    if (r != 9)
      lun[j++] = x10 + r + 1;
    i++;
  }

  cout << lun[K] << endl;
}


Error: 0

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)

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

  vector<ll> lun(K + 3);

  rep1(i, 10) { lun[i] = i; }

  int i = 1, j = 10;
  while (j <= K) {
    int r = lun[i] % 10;
    ll x10 = lun[i] * 10;
    if (r != 0)
      lun[j++] = x10 + r - 1;
    lun[j++] = x10 + r;
    if (r != 9)
      lun[j++] = x10 + r + 1;
    i++;
  }

  cout << lun[K] << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define mp make_pair
#define ll long long
#define SIZE 1005
using namespace std;
void io() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
ll k;
set<string> st;
int main() {
  io();
  cin >> k;
  queue<string> q;
  rep(i, 1, 9) q.push(to_string(i));
  vector<ll> vec;
  while (st.size() <= 2e5) {
    string top = q.front();
    q.pop();
    st.insert(top);
    if (top.back() != '9' && top.back() != '0') {
      char ch = top.back();
      --ch;
      q.push(top + ch);
      q.push(top + top.back());
      ch += 2;
      q.push(top + ch);
    } else if (top.back() == '0') {
      char ch = top.back();
      ++ch;
      q.push(top + top.back());
      q.push(top + ch);
    } else {
      char ch = top.back();
      --ch;
      q.push(top + ch);
      q.push(top + top.back());
    }
  }
  for (auto i : st) {
    // cout << i << '\\n';
    // ll num = stoi(i);
    vec.emplace_back((ll)stoll(i));
  }
  sort(vec.begin(), vec.end());
  // for (auto i : vec) cout << i << '\\n';
  cout << vec[k - 1];
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  stoi


Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define mp make_pair
#define ll long long
#define SIZE 1005
using namespace std;
void io() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
ll k;
set<string> st;
int main() {
  io();
  cin >> k;
  queue<string> q;
  rep(i, 1, 9) q.push(to_string(i));
  vector<ll> vec;
  while (st.size() <= 2e5) {
    string top = q.front();
    q.pop();
    st.insert(top);
    if (top.back() != '9' && top.back() != '0') {
      char ch = top.back();
      --ch;
      q.push(top + ch);
      q.push(top + top.back());
      ch += 2;
      q.push(top + ch);
    } else if (top.back() == '0') {
      char ch = top.back();
      ++ch;
      q.push(top + top.back());
      q.push(top + ch);
    } else {
      char ch = top.back();
      --ch;
      q.push(top + ch);
      q.push(top + top.back());
    }
  }
  for (auto i : st) {
    // cout << i << '\\n';
    // ll num = stoi(i);
    vec.emplace_back((ll)stoi(i));
  }
  sort(vec.begin(), vec.end());
  // for (auto i : vec) cout << i << '\\n';
  cout << vec[k - 1];
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

ll mod = 998244353;

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

  int k;
  cin >> k;
  if (k <= 9) {
    cout << k << endl;
    return 0;
  }
  vvi dp(k, vi(10));
  vi sum(k + 1);
  rep(i, 10) { dp[1][i] = 1; }
  sum[1] = 9;
  int num = 1;
  for (num = 2; num <= k; num++) {
    sum[num] = sum[num - 1];
    rep(d, 10) {
      dp[num][d] = dp[num - 1][d];
      if (d) {
        dp[num][d] += dp[num - 1][d - 1];
      }
      if (d < 9) {
        dp[num][d] += dp[num - 1][d + 1];
      }
      if (d)
        sum[num] += dp[num][d];
    }
    if (sum[num] >= k)
      break;
  }
  string ret = "";
  int cnt = sum[num - 1];
  int prev = 0;
  for (int d = 1; d <= 9; d++) {
    if (cnt + dp[num][d] >= k) {
      prev = d;
      ret += '0' + d;
      break;
    } else
      cnt += dp[num][d];
  }
  num--;
  while (num) {
    for (int d = prev - 1; d <= prev + 1; d++) {
      if (d >= 0 && d <= 9) {
        if (cnt + dp[num][d] >= k) {
          prev = d;
          ret += '0' + d;
          break;
        } else {
          cnt += dp[num][d];
        }
      }
    }
    num--;
  }
  cout << ret << endl;
}

Error: 0

Fixed submission:

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

ll mod = 998244353;

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

  int k;
  cin >> k;
  vvi dp(k, vi(10));
  vi sum(k + 1);
  rep(i, 10) { dp[1][i] = 1; }
  sum[1] = 9;
  int num = 1;
  for (num = 2; num <= k; num++) {
    sum[num] = sum[num - 1];
    rep(d, 10) {
      dp[num][d] = dp[num - 1][d];
      if (d) {
        dp[num][d] += dp[num - 1][d - 1];
      }
      if (d < 9) {
        dp[num][d] += dp[num - 1][d + 1];
      }
      if (d)
        sum[num] += dp[num][d];
    }
    if (sum[num] >= k)
      break;
  }
  string ret = "";
  int cnt = sum[num - 1];
  int prev = 0;
  for (int d = 1; d <= 9; d++) {
    if (cnt + dp[num][d] >= k) {
      prev = d;
      ret += '0' + d;
      break;
    } else
      cnt += dp[num][d];
  }
  num--;
  while (num) {
    for (int d = prev - 1; d <= prev + 1; d++) {
      if (d >= 0 && d <= 9) {
        if (cnt + dp[num][d] >= k) {
          prev = d;
          ret += '0' + d;
          break;
        } else {
          cnt += dp[num][d];
        }
      }
    }
    num--;
  }
  cout << ret << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, n, m) for (int i = n; i < m; ++i)
#define all(v) v.begin(), v.end()

using namespace std;
using ll = long long;

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

  ll n, m;
  string s;
  ll i, b, c = 0, sum = 0;
  queue<ll> q;

  cin >> n;

  rep2(i, 1, 10) { q.push(i); }

  for (i = 0; i < n - 1; ++i) {
    m = q.front();
    q.pop();
    if (m % 10 != 0) {
      q.push(10 * m + (m % 10) - 1);
    }
    q.push(10 * m + (m % 10));
    if (m % 10 != 9) {
      q.push(10 * m + (m % 10) + 1);
    }
  }
  cout << q.front() << endl;
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 1) >= this->size() (which is 1)


Fixed submission:

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, n, m) for (int i = n; i < m; ++i)
#define all(v) v.begin(), v.end()

using namespace std;
using ll = long long;

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

  int n, m;
  string s;
  int i, b, c = 0, sum = 0;
  map<int, int> memo;

  cin >> n;
  for (i = 0; c != n; i++) {
    s = to_string(i);
    for (int j = 0; j < s.size(); j++) {
      if (s.at(j) - s.at(j + 1) > 151 && j != s.size() - 1) {
        break;
      } else if (j == s.size() - 1) {
        c++;
        memo[c] = i + 1;
      }
    }
  }
  cout << memo.at(c);

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

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(), container.end()
#define fast                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0)
// #ifndef ONLINE_JUDGE
// #include "debug.cpp"
// #endif
#define int long long
const int mod = 1e9 + 7;
int power(int a, int b) {
  if (b == 0)
    return 1;
  int res = power(a, b / 2);
  if (b & 1)
    return res * res * a;
  else
    return res * res;
}

int32_t main() {

  fast;
  int k;
  cin >> k;
  vector<string> ans;

  for (int i = 1; i <= 9; i++) {
    string x = to_string(i);
    ans.pb(x);
  }

  int ptr = 0;

  for (int i = 10; i <= k; i++) {
    string x = ans[ptr];
    if (x[x.size() - 1] == '0') {
      ans.pb(x + '0');
      ans.pb(x + '1');
    } else if (x[x.size() - 1] == '9') {
      ans.pb(x + '8');
      ans.pb(x + '9');
    } else {
      char ch = x[x.size() - 1] - 1;
      for (int j = 1; j <= 3; j++) {
        ans.pb(x + ch);
        ch++;
      }
    }
    ptr++;
  }

  cout << ans[k - 1];

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(), container.end()
#define fast                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0)
// #ifndef ONLINE_JUDGE
// #include "debug.cpp"
// #endif
#define int long long
const int mod = 1e9 + 7;
int power(int a, int b) {
  if (b == 0)
    return 1;
  int res = power(a, b / 2);
  if (b & 1)
    return res * res * a;
  else
    return res * res;
}

int32_t main() {

  fast;
  int n, k;
  cin >> n >> k;

  if (n < k) {
    cout << min(n, abs(n - k));
  } else {
    int x = n / k;
    if (n % k != 0)
      x++;
    cout << n - x * k;
  }

  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;
    } else {
      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);
        }
      }
    }
  }
}

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;
    } else {
      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);
        }
      }
    }
  }
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;
typedef long long ll;
const int N = 1e5 + 10;

void solved() {
  int k;
  cin >> k;
  queue<ll> q;
  for (int i = 1; i <= 9; i++)
    q.push(i);

  while (1) {
    auto ans = q.front();
    q.pop();
    k--;
    if (!k) {
      cout << ans;
      return;
    }
    int t = ans % 10;
    if (t)
      q.push(ans * 10 + t - 1);
    q.push(ans * 10 + t);
    if (t < 9)
      q.push(ans * 10 + t + 1);
  }
}

int main() {
#ifdef ONLINE_JUDGE
  // ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#endif
  int t = 1;
  solved();
#ifdef LOCAL
  system("pause");
#endif

  return 0;
}

Error: TLE

Fixed submission:

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

signed main() {
  int ans = 0;
  int k;
  cin >> k;
  for (int i = 1;; i++) {
    string t = to_string(i);
    int n = t.size();
    if (n == 1) {
      ans++;
      if (ans == k) {
        cout << i;
        return 0;
      }
      continue;
    }
    int flag = 1;
    for (int j = 1; j < n; j++) {
      if (abs(t[j] - t[j - 1]) > 1) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      ans++;
      if (ans == k) {
        cout << i;
        return 0;
      }
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf ll(10e15)
short int isL(ll n) {
  ll last = n % 10;
  n /= 10;
  while (n) {
    if (abs(n % 10 - last) > 1)
      return false;
    last = n % 10;
    n /= 10;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll t;
  t = 1;
  while (t--) {
    ll n, count = 0, i;
    cin >> n;
    queue<ll> q;
    for (int j = 1; j < 10; ++j)
      q.push(j);

    while (count < n) {
      i = q.front();
      q.pop();
      if (i % 10)
        q.push(10 * i + i % 10 - 1);

      q.push(10 * i + i % 10);

      if (i % 10 != 9)
        q.push(10 * i + i % 10 + 1);
      ++count;
    }
    cout << i << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf ll(10e15)
short int isL(ll n) {
  ll last = n % 10;
  n /= 10;
  while (n) {
    if (abs(n % 10 - last) > 1)
      return false;
    last = n % 10;
    n /= 10;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll t;
  t = 1;
  while (t--) {
    ll n, count = 0, i;
    cin >> n;
    for (i = 1; count < n; ++i) {
      if (isL(i)) {
        ++count;
      }
    }
    cout << i - 1 << endl;
  }
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
using namespace std;

int main(int argc, char *argv[]) {
  int K;
  scanf("%d", &K);

  queue<long long> A;

  for (long long i = 0; i < 9; i++) {
    A.push(i + 1);
  }

  for (int i = 0; i < K - 1; i++) {
    long long x = A.front();
    if (x % 10 == 0) {
      A.push(x * 10 + 0);
      A.push(x * 10 + 1);
    } else if (x % 10 == 9) {
      A.push(x * 10 + 8);
      A.push(x * 10 + 9);
    } else {
      A.push(x * 10 + x % 10 - 1);
      A.push(x * 10 + x % 10 + 0);
      A.push(x * 10 + x % 10 + 1);
    }
    A.pop();
  }

  long long y = A.front();

  printf("%lld\\n", y);

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;

bool isLunlun(long num) {

  long digit = (long)log10((double)num) + 1;

  if (digit == 1) {
    //		printf("%ld\\n", num);
    return true;
  } else {
    long big_digit, small_digit;
    int flag = 0;

    for (int i = 0; i < digit - 1; i++) {
      long x = num % (long)pow(10.0, ((double)i + 1.0));
      x = x / (long)pow(10.0, (double)i);
      small_digit = x;

      long y = num % (long)pow(10.0, ((double)i + 2.0));
      y = y / (long)pow(10.0, ((double)i + 1.0));
      big_digit = y;

      if (abs(big_digit - small_digit) > 1) {
        flag = 1;
        break;
      }
    }

    if (flag == 0) {
      //			printf("%ld\\n", num);
      return true;
    } else {
      return false;
    }
  }
}

int main(int argc, char *argv[]) {
  int K;
  scanf("%d", &K);

  long num;
  int count = 0;

  for (num = 1; count < K; num++) {
    if (isLunlun(num) == 1) {
      count++;
    } else {
    }
  }

  printf("%ld\\n", num - 1);

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

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

vector<long long> v;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int k;
  cin >> k;
  for (int i = 1; i < 10; i++)
    v.push_back(i);
  int i = 0;
  while (v.size() < k) {
    long long a = v[i];
    int d = a % 10;
    if (d > 0)
      v.push_back(a * 10 + d - 1);
    v.push_back(a * 10 + d);
    if (d + 1 < 10)
      v.push_back(a * 10 + d + 1);
    i++;
  }
  cout << v[k - 1] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int b[100005];

int main() {
  int k;
  cin >> k;
  int j = 10;
  if (k <= 10) {
    cout << k << endl;
    return 0;
  }
  for (int i = 11;; i++) {
    int x = i;
    while (abs(x % 10 - x / 10 % 10) <= 1) {
      x = x / 10;
      if (x < 10)
        break;
    }
    if (x >= 0 && x <= 10) {
      b[++j] = i;
    }
    if (j == k)
      break;
  }
  cout << b[k] << endl;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <set>
#include <unordered_set>
#include <vector>
using namespace std;

unordered_set<string> generate_lun(int n) {
  if (n == 1) {
    unordered_set<string> st;
    st.insert("0");
    st.insert("1");
    st.insert("2");
    return st;
  } else {
    unordered_set<string> r2;
    unordered_set<string> r = generate_lun(n - 1);
    for (auto it : r) {
      r2.insert("0" + it);
      r2.insert("1" + it);
      r2.insert("2" + it);
    }
    return r2;
  }
}

bool check_lun(long long int k) {
  long long int prev = k % 10, cp = k / 10;
  // if()
  while (cp > 0) {
    if (abs(prev - cp % 10) > 1)
      return false;
    prev = cp % 10;
    cp /= 10;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  set<long long int> v;
  for (int i = 1; i <= 9; i++) {
    unordered_set<string> st = generate_lun(i);
    for (auto it : st) {
      int pref = 0;
      int mn = 20, mx = -20;
      for (int j = 0; j < it.size(); j++) {
        pref += it[j] - 48 - 1;
        mn = min(pref, mn);
        mx = max(pref, mx);
      }
      int s = 0;
      if (mn >= 0)
        s = 1;
      else
        s = abs(mn);
      for (int j = s; j <= min(9 - mx, 9); j++) {
        long long int d = j;
        for (int k = 0; k < it.size(); k++) {
          d = d * 10 + (d % 10 + it[k] - 48 - 1);
        }
        v.insert(d);
      }
    }
  }
  for (int i = 1; i <= 9; ++i) {
    v.insert(i);
  }
  auto it = v.begin();
  for (int i = 0; i < n - 1; ++i) {
    it++;
  }
  cout << *it;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
// TODO add string to vector of integers macro or function
vector<int> str_to_vect(string s) {
  vector<int> v;
  for (int i = 0; i < s.size(); ++i) {
    v.push_back((int)s[i] - 48);
  }
  return v;
}
bool check_lun(int k) {
  int prev = k % 10, cp = k / 10;
  while (cp > 0) {
    if (abs(prev - cp % 10) > 1)
      return false;
    prev = cp % 10;
    cp /= 10;
  }
  return true;
}
int main() {
  int n = 100000;
  vector<int> v;
  for (int i = 1; i < n; ++i) {
    if (check_lun(i))
      v.push_back(i);
  }
  // for (int i = 0; i < 20; ++i)
  // {
  // 	cout<<v[i]<<" ";
  // }
  int k;
  cin >> k;
  cout << v[k - 1];
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define sort(A) sort(A.begin(), A.end())
#define reverse(A) reverse(A.begin(), A.end())
typedef long long ll;

int main() {
  int k;
  cin >> k;
  vector<ll> ans(9);
  rep(i, 9) ans[i] = i + 1;
  for (int i = 0; i < 100000; i++) {
    int m = ans[i] % 10;
    if (m > 0)
      ans.push_back(10 * ans[i] + m - 1);
    ans.push_back(10 * ans[i] + m);
    if (m < 9)
      ans.push_back(10 * ans[i] + m + 1);
  }
  cout << ans[k - 1] << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define sort(A) sort(A.begin(), A.end())
#define reverse(A) reverse(A.begin(), A.end())
typedef long long ll;

bool isL(ll a) {
  if (a < 10)
    return 1;
  int x = a % 10;
  int y = (a % 100) / 10;
  if (abs(x - y) <= 1)
    return isL(a / 10);
  else
    return 0;
}

int main() {
  vector<ll> L(0);
  for (ll i = 1; i <= 100000001; i++) {
    if (isL(i))
      L.push_back(i);
  }
  int k;
  cin >> k;
  cout << L[min(k - 1, 100000000)] << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// using queue
int main() {
  int64_t K;
  cin >> K;
  queue<int64_t> L;
  for (int i = 1; i <= 9; i++) {
    L.push(i);
  }
  int64_t count;
  int64_t x;
  for (count = 1; count <= K; count++) {
    x = L.front();
    if (x % 10 != 0)
      L.push(x * 10 + (x % 10) - 1);
    L.push(x * 10 + (x % 10));
    if (x % 10 != 9)
      L.push(x * 10 + (x % 10) + 1);
    L.pop();
  }
  cout << x << endl;
}

Error: TLE

Fixed submission:

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

// index increment でそのままやる
bool isLunLun(int64_t n) {
  bool state = true;
  string s = to_string(n);
  char check;
  for (int i = 0; i < s.size() - 1; i++) {
    check = s.at(i + 1) - s.at(i);
    if (check > 1 || check < -1) {
      state = false;
    }
  }
  return state;
}

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n, a, b, c;
  cin >> n;
  vector<ll> vec(9);
  for (ll i = 0; i < 9; i++) {
    vec.at(i) = i + 1;
  }
  ll count = 9;
  ll j = 0;
  if (n <= 9) {
    cout << n << endl;
  } else {
    while (count < n) {
      if (vec.at(j) % 10 != 0) {
        a = 10 * vec.at(j) + vec.at(j) % 10 - 1;
        vec.push_back(a);
        count += 1;
      }
      if (count == n) {
        cout << a << endl;
        break;
      }
      b = 10 * vec.at(j) + vec.at(j) % 10;
      vec.push_back(b);
      count += 1;
      if (count == n) {
        cout << b << endl;
        break;
      }
      if (vec.at(j) % 10 != 9) {
        c = 10 * vec.at(j) + vec.at(j) % 10 + 1;
        vec.push_back(c);
        count += 1;
      }
      if (count == n) {
        cout << c << endl;
        break;
      }
      j++;
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
std::string str;
int main() {
  int k;
  cin >> k;
  if (k < 10) {
    cout << k << endl;
  } else {
    long long count = 9;
    for (long long i = 10; i > 0; i++) {
      string str1 = std::to_string(i);
      int number = 0;
      for (int j = 0; j <= str1.size() - 2; j++) {
        int character1 = str1.at(j) - '0';
        int character2 = str1.at(j + 1) - '0';
        if (-1 <= character1 - character2 && character1 - character2 <= 1) {
          number++;
        }
        if (number == str1.size() - 1) {
          count++;
        }
      }
      if (count == k) {
        cout << i << endl;
        break;
      }
    }
  }
}