Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep0(n) for (int i = 0; i < (int)(n); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define from1(obj) obj.begin() + 1, obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\\n"
#define dbp(p) cerr << #p << ":(" << p.first << ", " << p.second << ") "
#define dbpl(p) cerr << #p << ":(" << p.first << ", " << p.second << ")\\n"
#define dbt3(t3)                                                               \\
  cerr << #t3 << ":(" << get<0>(t3) << ", " << get<1>(t3) << ", "              \\
       << get<2>(t3) << ") "
#define dbt3l(t3)                                                              \\
  cerr << #t3 << ":(" << get<0>(t3) << ", " << get<1>(t3) << ", "              \\
       << get<2>(t3) << ")\\n"
#define dbt4(t4)                                                               \\
  cerr << #t4 << ":(" << get<0>(t4) << ", " << get<1>(t4) << ", "              \\
       << get<2>(t4) << ", " << get<3>(t4) << ") "
#define dbt4l(t4)                                                              \\
  cerr << #t4 << ":(" << get<0>(t4) << ", " << get<1>(t4) << ", "              \\
       << get<2>(t4) << ", " << get<3>(t4) << ")\\n"
#define dbv(vec)                                                               \\
  cerr << #vec << ":{ ";                                                       \\
  for (auto e : vec)                                                           \\
    cerr << e << ", ";                                                         \\
  cerr << "}\\n"
#define dbvp(vec)                                                              \\
  cerr << #vec << ":{ ";                                                       \\
  for (auto p : vec)                                                           \\
    cerr << "(" << p.first << ", " << p.second << "), ";                       \\
  cerr << "}\\n"
#define dbvv(vv)                                                               \\
  cerr << #vv << ":{\\n";                                                       \\
  for (auto vec : vv) {                                                        \\
    cerr << "{ ";                                                              \\
    for (auto e : vec)                                                         \\
      cerr << e << ", ";                                                       \\
    cerr << "}\\n";                                                             \\
  }                                                                            \\
  cerr << "}\\n"
#define dbm(map)                                                               \\
  cerr << #map << ":{ ";                                                       \\
  for (auto p : map)                                                           \\
    cerr << "(" << p.first << ", " << p.second << "), ";                       \\
  cerr << "}\\n"
#define YN(f) cout << (f ? "YES" : "NO") << "\\n"
#define Yn(f) cout << (f ? "Yes" : "No") << "\\n"
#define yn(f) cout << (f ? "yes" : "no") << "\\n"
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using ti3 = tuple<int, int, int>;
using tl3 = tuple<ll, ll, ll>;
using ti4 = tuple<int, int, int, int>;
using tl4 = tuple<ll, ll, ll, ll>;
using mii = map<int, int>;
using mil = map<int, ll>;
using mll = map<ll, ll>;
using mli = map<ll, int>;

int main() {
  int K;
  cin >> K;
  vvi g(10, vi());
  g[0] = {0, 1};
  rep2(i, 1, 9) g[i] = {i - 1, i, i + 1};
  g[9] = {8, 9};
  // dbvv(g);
  queue<ll> q;
  rep2(i, 1, 10) q.push((ll)i);
  int cnt = 0;
  while (true) {
    cnt++;
    ll x = q.front();
    q.pop();
    // db(cnt); dbl(u);
    if (cnt == K) {
      cout << x << endl;
      break;
    }
    for (int v : g[x % 10]) {
      q.push(10 * x + v);
    }
  }
}

Error: 0

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep0(n) for (int i = 0; i < (int)(n); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define from1(obj) obj.begin() + 1, obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\\n"
#define dbp(p) cerr << #p << ":(" << p.first << ", " << p.second << ") "
#define dbpl(p) cerr << #p << ":(" << p.first << ", " << p.second << ")\\n"
#define dbt3(t3)                                                               \\
  cerr << #t3 << ":(" << get<0>(t3) << ", " << get<1>(t3) << ", "              \\
       << get<2>(t3) << ") "
#define dbt3l(t3)                                                              \\
  cerr << #t3 << ":(" << get<0>(t3) << ", " << get<1>(t3) << ", "              \\
       << get<2>(t3) << ")\\n"
#define dbt4(t4)                                                               \\
  cerr << #t4 << ":(" << get<0>(t4) << ", " << get<1>(t4) << ", "              \\
       << get<2>(t4) << ", " << get<3>(t4) << ") "
#define dbt4l(t4)                                                              \\
  cerr << #t4 << ":(" << get<0>(t4) << ", " << get<1>(t4) << ", "              \\
       << get<2>(t4) << ", " << get<3>(t4) << ")\\n"
#define dbv(vec)                                                               \\
  cerr << #vec << ":{ ";                                                       \\
  for (auto e : vec)                                                           \\
    cerr << e << ", ";                                                         \\
  cerr << "}\\n"
#define dbvp(vec)                                                              \\
  cerr << #vec << ":{ ";                                                       \\
  for (auto p : vec)                                                           \\
    cerr << "(" << p.first << ", " << p.second << "), ";                       \\
  cerr << "}\\n"
#define dbvv(vv)                                                               \\
  cerr << #vv << ":{\\n";                                                       \\
  for (auto vec : vv) {                                                        \\
    cerr << "{ ";                                                              \\
    for (auto e : vec)                                                         \\
      cerr << e << ", ";                                                       \\
    cerr << "}\\n";                                                             \\
  }                                                                            \\
  cerr << "}\\n"
#define dbm(map)                                                               \\
  cerr << #map << ":{ ";                                                       \\
  for (auto p : map)                                                           \\
    cerr << "(" << p.first << ", " << p.second << "), ";                       \\
  cerr << "}\\n"
#define YN(f) cout << (f ? "YES" : "NO") << "\\n"
#define Yn(f) cout << (f ? "Yes" : "No") << "\\n"
#define yn(f) cout << (f ? "yes" : "no") << "\\n"
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using ti3 = tuple<int, int, int>;
using tl3 = tuple<ll, ll, ll>;
using ti4 = tuple<int, int, int, int>;
using tl4 = tuple<ll, ll, ll, ll>;
using mii = map<int, int>;
using mil = map<int, ll>;
using mll = map<ll, ll>;
using mli = map<ll, int>;

int main() {
  int K;
  cin >> K;
  vvi g(10, vi());
  g[0] = {0, 1};
  rep2(i, 1, 9) g[i] = {i - 1, i, i + 1};
  g[9] = {8, 9};
  // dbvv(g);
  queue<int> q;
  rep2(i, 1, 10) q.push(i);
  int cnt = 0, ans;
  while (true) {
    cnt++;
    int u = q.front();
    q.pop();
    // db(cnt); dbl(u);
    if (cnt == K) {
      ans = u;
      break;
    }
    for (int v : g[u % 10]) {
      q.push(10 * u + v);
    }
  }
  cout << ans << endl;
}