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

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i > ll(b); i--)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Umap unordered_map
#define Uset unordered_set

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll N;
  cin >> N;

  string alphabet = "abcdefghijklmnopqrstuvwxyz";
  string ans = "";
  while (N > 0) {
    ll mozi = N % 26;
    if (mozi == 0)
      mozi = 26;
    ans.push_back(alphabet.at(mozi - 1));

    N -= mozi;
    N = N / 26;
  }
  reverse(ans.begin(), ans.end());

  cout << ans << endl;

  return 0;
}

Error: WA

Fixed submission:

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i > ll(b); i--)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Umap unordered_map
#define Uset unordered_set

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll N;
  cin >> N;

  string alphabet = "abcdefghijklmnopqrstuvwxyz";
  string ans = "";
  while (N > 26) {
    ll mozi = N % 26;
    ans.push_back(alphabet.at(mozi - 1));
    N = N / 26;
  }
  // if (N!=0) ans.push_back(alphabet.at(N-1));
  reverse(ans.begin(), ans.end());

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; // intじゃ扱えないことに注意！
using P = pair<int, int>;
#define rep(i, n)                                                              \\
  for (int i = 0; i < (int)(n); i++) // 範囲外参照とループの初期化に注意！

string f(ll n) {
  if (n == 0)
    return "";
  n--;
  return f(n / 26) + string(1, 'a' + n % 26);
}
int main() {
  ll n;
  cin >> n;
  cout << f(n) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; // intじゃ扱えないことに注意！

#define rep(i, n)                                                              \\
  for (int i = 0; i < (int)(n); i++) // 範囲外参照とループの初期化に注意！
const double pi = 3.14159265359;

int main() {
  ll N;
  cin >> N;

  string ans = "";
  string alpha = "abcdefghijklmnopqrstuvwxyz";

  while (N != 0) {
    int xx = N % 26;
    if (xx != 0) {
      xx--;
      N /= 26;
      ans = alpha[xx] + ans;
    } else {
      string a = "z";
      ans == a + ans;
    }
  }
  cout << ans << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

using namespace std;

int main() {
  long N;
  cin >> N;
  N--;
  string a_to_z = "abcdefghijklmnopqrstuvwxyz";
  string name = "";
  long max = 0;
  long x = 1;
  long M = N;
  do {
    name = a_to_z.substr(N % 26, 1) + name;
    N = (N - 26) / 26;
    x *= 26;
    max += x;
  } while (M >= max);
  cout << name;
}

Error: WA

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  long N;
  cin >> N;
  N--;
  string a_to_z = "abcdefghijklmnopqrstuvwxyz";
  string name = "";
  int max = 0;
  long x = 1;
  long M = N;
  do {
    name = a_to_z.substr(N % 26, 1) + name;
    N = (N - 26) / 26;
    x *= 26;
    max += x;
  } while (M >= max);
  cout << name;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll n;
  cin >> n;
  string ans = "";
  while (n > 0) {
    n--;
    ans += 'a' + n % 26;
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}

Error: WA

Fixed submission:

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

string alphabet = "abcdefghijklmnopqrstuvwxyz";

int main() {
  int n, r;
  cin >> n;
  string s;
  while (n % 26 != 0) {
    r = n % 26;
    s.push_back(alphabet[r - 1]);
    n /= 26;
  }
  s.push_back(alphabet[n - 1]);
  reverse(s.begin(), s.end());
  cout << s << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define out(n) cout << n << '\\n'
#define rep(i, n) for (ll i = 0; i < (n); i++)
const int inf = 1000000000;
const ll linf = (ll)inf * (ll)inf;
void solve() {
  ll n;
  in(n);
  string s = "";
  int count = 0;
  while (n > 0) {
    n -= 1;
    int k = n % 26;
    char c = 'a' + k;
    s = c + s;
    n /= 26;
  }
  out(s);
}

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define out(n) cout << n << '\\n'
#define rep(i, n) for (ll i = 0; i < (n); i++)
const int inf = 1000000000;
const ll linf = (ll)inf * (ll)inf;
void solve() {
  ll n;
  in(n);
  string s = "";
  int count = 0;
  while (n >= 0) {
    int k = n % 26;
    char c = 'a' + k - 1;
    s = c + s;
    n /= 26;
  }
  out(s);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
  ll N;
  cin >> N;
  vector<char> cs;
  int q;
  while (N != 0) {
    q = N % 26;
    if (q == 0) {
      cs.push_back('z');
      N -= 26;
    } else {
      cs.push_back('a' + q - 1);
      N -= q;
    }
    N /= 26;
  }
  for (int i = (int)cs.size() - 1; i >= 0; i--) {
    cout << cs[i];
  }
  cout << endl;
}

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


Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
  ll N;
  cin >> N;
  vector<int> ns;
  int di;
  string s = "";
  while (N != 0) {
    di = N % 26;
    N /= 26;
    if (di == 0) {
      ns.push_back(26);
    } else {
      ns.push_back(di);
    }
  }
  for (int i = (int)ns.size() - 1; i >= 0; i++) {
    s += (char)('a' + ns.at(i) - 1);
  }
  cout << s << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

string f(ll n) {
  if (n == 0)
    return "";
  //-1
  n--;
  return f(n / 26) + string(1, 'a' + n % 26);
}

int main() {
  ll n;
  cin >> n;

  cout << f(n) << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MAX 1000
int main() {
  int n, k, x, ans = 0;
  cin >> n >> k;
  vector<int> p;
  for (int i = 0; i < n; i++) {
    cin >> x;
    p.push_back(x);
  }
  sort(p.begin(), p.end());
  for (int i = 0; i < k; i++)
    ans += p[i];
  cout << ans << endl;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

int main() {
  long long n;
  cin >> n;

  int i = 0;
  vector<char> ans(12, 0);
  while (n > 0) {
    int mod = (n - 1) % 26;
    ans[i] = mod + 0x61;
    n -= mod;
    n /= 26;
    i++;
  }

  for (int j = i - 1; j >= 0; j--)
    cout << ans[j];
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

int main() {
  while (1) {
    int n;
    cin >> n;

    int i = 0;
    vector<char> ans(12, 0);
    while (n > 0) {
      int mod = (n - 1) % 26;
      ans[i] = mod + 0x61;
      n -= mod;
      n /= 26;
      i++;
    }

    for (int j = i - 1; j >= 0; j--)
      cout << ans[j];
    cout << endl;
  }

  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

typedef long long ll;

int main() {
  ll N;
  cin >> N;
  vector<int> digits;
  while (N > 0) {
    int tmp = N % 26;
    if (tmp == 0) {
      tmp = 26;
      N--;
    }
    digits.push_back(tmp);
    N /= 26;
    if (N < 26) {
      if (N > 0)
        digits.push_back(N);
      break;
    }
  }
  reverse(digits.begin(), digits.end());
  for (int d : digits) {
    cout << alphabet[d - 1];
  }
  cout << "\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

typedef long long ll;

int main() {
  ll N;
  cin >> N;
  vector<int> digits;
  while (true) {
    int tmp = N % 26;
    if (tmp == 0) {
      digits[digits.size() - 1]--;
      tmp = 26;
    }
    digits.push_back(tmp);
    N /= 26;
    if (N < 26) {
      if (N > 0)
        digits.push_back(N);
      break;
    }
  }
  reverse(digits.begin(), digits.end());
  for (int d : digits) {
    cout << alphabet[d - 1];
  }
  cout << "\\n";
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {

  long long int n;
  scanf("%lld", &n);
  int i = 0, temp;
  ;
  char word[100];
  while (n > 0) {
    temp = 0;
    temp = n % 26;
    if (temp == 0) {
      word[i] = 'z';
      n = n / 26 - 1;
    } else {
      word[i] = temp + 'a' - 1;
      n /= 26;
    }
    //		n/=26;
    //		printf("%c", temp+'a'-1);
    i++;
  }
  //	printf("%d", i);
  word[i] = '\\0';
  for (int j = i - 1; j >= 0; j--) {
    printf("%c", word[j]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>

int main() {
  long long int n;
  scanf("%d", &n);
  int count = 0;
  char out[255];
  while (n >= 0) {
    n -= 1;
    out[count] = (n % 26) + 'a';
    n /= 26;
    count++;
  }
  for (int i = strlen(out) - 1; i >= 0; i--) {
    printf("%c", out[i]);
  }
  puts("");

  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef pair<string, string> Pstring;
typedef pair<double, double> Pdouble;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REP1(i, n) for (ll i = 1; i <= n; i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI = 3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1 << 29;
using Graph = vector<vector<int>>;

int main() {
  ll n;
  cin >> n;

  ll cnd = 1;
  ll pn = n;
  while (true) {
    if (pn <= pow(26, cnd)) {
      break;
    } else {
      pn -= pow(26, cnd);
      cnd++;
    }
  }
  ll cou2 = cnd - 1;
  pn--;
  vector<ll> ans;

  while (true) {
    ll waru = pow(26, cou2);
    ll na = pn / waru;
    ans.push_back(na);
    pn -= na * waru;
    if (cou2 == 0) {
      break;
    }
    cou2--;
  }

  REP(i, ans.size()) {
    char sss = 'a' + ans[i];
    cout << sss;
    if (i == ans.size() - 1)
      cout << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef pair<string, string> Pstring;
typedef pair<double, double> Pdouble;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REP1(i, n) for (ll i = 1; i <= n; i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI = 3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1 << 29;
using Graph = vector<vector<int>>;

int main() {
  ll n;
  cin >> n;

  ll cnd = 1;
  ll count = 0;
  while (n > cnd) {
    cnd *= 26;
    count++;
  }
  ll cou2 = count - 1;
  vector<ll> ans;
  while (true) {
    ll waru = pow(26, cou2);
    ll na = n / waru;
    ans.push_back(na);
    n = n % waru;
    if (cou2 == 0) {
      break;
    }
    cou2--;
  }

  REP(i, ans.size()) {
    char sss = 'a' + ans[i] - 1;
    cout << sss;
    if (i == ans.size() - 1)
      cout << endl;
  }
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <numeric>
#include <sstream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
using pint = pair<int, int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  string ans;
  while (n) {
    n--;
    ans += ('a' + n % 26);
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}

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:

#include <bits/stdc++.h>
using namespace std;
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
using pint = pair<int, int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  char moji;
  int cnt = 0;

  string name = "a";
  int k = name.size(), cnt2 = 0;
  for (int i = 0; i < n; i++) {
    if (i + 1 == 26 * (pow(26, cnt + 1) / 25)) {
      k = name.size();
      cnt2 = 0;
      cnt++;
      name += 'a';
    }
    if (i + 1 == 26 * pow(26, cnt2 + 1) / 25) {
      cnt2++;
    }
    for (moji = 'a'; moji <= 'z'; moji++) {
      name.at(k) = moji;
      if (moji == 'z')
        k--;
    }
  }

  cout << name << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;

int main() {
  ll a = 1, b = 0;
  vector<ll> S = {0};
  rep(i, 100) {
    a *= 26;
    b += a;
    S.push_back(b);
  }
  ll N;
  cin >> N;
  int k = 0;
  rep(i, 101) {
    if (S[i] >= N) {
      N -= S[i - 1];
      k = i;
      break;
    }
  }
  vector<int> ans(k, 0);
  --N;
  for (int i = k - 1; i >= 0; --i) {
    ans[i] = N % 26;
    N /= 26;
  }
  rep(i, k) cout << (char)('a' + ans[i]);
  cout << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;

int main() {
  ll N;
  cin >> N;

  int n = 0;
  ll c = 1, d = 0;
  while (d < N) {
    c *= 26;
    d += c;
    ++n;
  }
  --N;
  vector<int> S;
  while (N) {
    S.push_back(N % 26);
    N /= 26;
  }
  reverse(ALL(S));
  rep(i, n - 1) cout << (char)('a' + S[i] - 1);
  cout << (char)('a' + S[n - 1]) << "\\n";
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using ul = unsigned long;
using namespace std;

int main() {
  long n;
  cin >> n;

  string ans = "";

  long nn;
  rep(i, 15) {
    if (n > (pow(26, i) - 1) / 25 * 26 && n <= (pow(26, i + 1) - 1) / 25 * 26) {
      nn = i;
      break;
    }
  }
  // nnは桁数-1
  n -= (pow(26, nn) - 1) / 25 * 26;
  while (nn >= 0) {
    long b = (n - 1) / pow(26, nn);
    ans += 'a' + b;
    n -= pow(26, nn) * b;
    nn--;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (long i = long(s); i < long(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

using ll = long long;
using namespace std;

int main() {
  ll n;
  cin >> n;

  string ans = "";
  ll nn;
  rep(i, 10) {
    if (n > (pow(26, i) - 1) / 25 * 26 && n <= (pow(26, i + 1) - 1) / 25 * 26) {
      nn = i + 1;
      break;
    }
  }
  // nnは桁数
  while (n > 26) {
    n -= (pow(26, nn - 1) - 1) / 25 * 26;
    rep(i, 26) {
      ll base = pow(26, nn - 1);
      if (n > base * i && n <= base * (i + 1)) {
        ans += 'a' + i;
        n -= base * i;
        break;
      }
    }
    n += (pow(26, nn - 2) - 1) / 25 * 26;
    nn--;
  }
  ans += 'a' + (n - 1);
  cout << ans << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long N;
  cin >> N;
  vector<char> alpha(26);
  vector<long long> tmp(1000, 9999);
  string ans;
  rep(i, 26) { alpha[i] = 'a' + i; }

  long long x = N;
  for (int i = 0; x > 0; i++) {
    if (x % 26 == 0) {
      tmp[i] = 26;
      x--;
    } else {
      tmp[i] = (long long)(x % 26);
    }
    if (x == 26)
      break;
    x /= 26;
    // cout << alpha[tmp[i]-1] << " ";
  }

  int i = 0;
  while (tmp[i] != 9999) {
    if (alpha[tmp[i] - 1] == ' ')
      continue;
    ans.push_back(alpha[tmp[i] - 1]);
    // cout << alpha[tmp[i]-1] << " ";
    i++;
  }
  reverse(ans.begin(), ans.end());

  cout << ans << endl;
  return 0;
}

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


Fixed submission:

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

int main() {
  long long N;
  cin >> N;
  vector<char> alpha(26);
  vi tmp(1000000000);
  string ans;
  rep(i, 26) { alpha[i] = 'a' + i; }

  for (int i = 0; N > 26; i++) {
    tmp[i] = (N % 26) + 1;
    N /= 26;
  }

  for (int i = 0; tmp[i] != 0; i++) {
    ans += alpha[tmp[i] - 2];
  }
  reverse(ans.begin(), ans.end());

  cout << ans << endl;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)

using namespace std;
using ll = long long;

int main(int argc, char **argv) {

  ll x = 0;
  cin >> x;
  vector<int> ret;
  while (x > 26) {
    int q = x % 26;
    if (q == 0)
      q = 26;
    ret.push_back(q);
    ll p = (x - q) / 26;
    x = p;
  }
  ret.push_back(x);
  rep(i, ret.size()) {
    char c = 'a' + ret[(ret.size() - 1) - i] - 1;
    printf("%c", c);
  }
  printf("\\n");
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)

using namespace std;
using ll = long long;

int main() {

  ll a;
  cin >> a;
  char c;
  vector<char> ret;
  ll x = a;
  while (x > 26) {
    int i = 0;
    for (i = 1; i <= x / 26; i++) {
      if (26 * i < x && x <= 26 * (i + 1))
        break;
    }

    int rest = x - (26 * i);
    c = 'a' + rest - 1;
    ret.push_back(c);
    x = i;
  }
  c = 'a' + (int)x - 1;
  ret.push_back(c);

  rep(i, ret.size()) { printf("%c", ret[ret.size() - i - 1]); }
  printf("\\n");
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  long long n;
  cin >> n;
  string ans = "";
  string abc = "abcdefghijklmnopqrstuvwxyz";
  int rem;
  while (n > 0) {
    n -= 1;
    rem = n % 26;
    ans += abc[rem];
    n /= 26;
  }

  reverse(ans.begin(), ans.end());
  cout << ans;

  return 0;
}


Error: TLE

Fixed submission:

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

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

  long long n;
  cin >> n;
  string ans = "";
  string abc = "abcdefghijklmnopqrstuvwxyz";
  int rem;
  while (n >= 0) {
    n -= 1;
    rem = n % 26;
    ans += abc[rem];
    n /= 26;
  }

  reverse(ans.begin(), ans.end());
  cout << ans;

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

#include <bits/stdc++.h>
using namespace std;
long long n, b = 1;
int ans = 0, a[1001];
int main() {
  cin >> n;
  for (int i = 1; i >= 1; i++) {
    if (b + pow(26, ans + 1) > n)
      break;
    b += ceil(pow(26, ans + 1));
    ans++;
  }
  n -= b;
  for (int i = 0; i <= ans; i++) {
    a[i + 1] = n % 26;
    n /= 26;
  }
  for (int i = ans + 1; i >= 1; i--)
    cout << char(a[i] + 'a');
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
unsigned long long n;
string s = "a";
unsigned long long ans = 1, sum = 1;
void plu() {
  int x = 0;
  for (int i = s.size() - 1; i >= 0; i--) {
    if (i == s.size() - 1 || x == 1)
      s[i]++, x = 0;
    if (s[i] > 'z')
      s[i] = 'a', x = 1;
  }
  if (x == 1)
    s.insert(0, "a");
}
int main() {
  cin >> n;
  for (unsigned long long i = 1; i <= 1000000000000001; i++) {
    if (ans == n)
      cout << s, exit(0);
    else {
      plu();
    }
    ans++;
  }
}