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

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

int main() {
  long long int n;
  cin >> n;
  string a = "abcdefghijklmnopqrstuvwxyz";
  string ret = "";

  while (n > 0) {
    --n;
    ret += a[(int)(n % 26)];
    n /= 26;
  }
  reverse(ret.begin(), ret.end());
  cout << ret << endl;
  return 0;
}

// 9223372036854775807 -> long long int max value
// 1000000000000001    -> problem size


Error: WA

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int &Ai : A) {
    cin >> Ai;
  }
  int Q;
  cin >> Q;
  vector<int> B(Q);
  vector<int> C(Q);
  for (int i = 0; i < Q; ++i) {
    int bi, ci;
    cin >> bi >> ci;
    B[i] = bi;
    C[i] = ci;
  }

  // Value Ai --> the i where Ai is located
  unordered_map<int, vector<int>> locations;
  for (int i = 0; i < N; ++i) {
    locations[A[i]].push_back(i);
  }

  int sum = 0;
  for (int Ai : A)
    sum += Ai;
  for (int i = 0; i < Q; ++i) {
    // replace elements whose value is Bi into Ci
    int Bi = B[i];
    int Ci = C[i];
    if (Bi != Ci) {
      vector<int> locs = locations[Bi];
      locations[Bi].clear();
      int nl = locs.size();
      sum += nl * (Ci - Bi);
      for (int ii : locs) {
        A[ii] = Ci;
        locations[Ci].push_back(ii);
      }
    }
    // sum += nl * (Ci - Bi);
    // locations[Bi].clear();

    cout << sum << endl;
  }

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

#include <cassert>
#include <cmath>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
using namespace std;

int main() {
  long long N;
  cin >> N;
  assert(N >= 1);

  const string alphabets = "abcdefghijklmnopqrstuvwxyz";
  const long long MAX_N = 1000000000000001;
  const int M = 26;

  int j = 1000000000;
  long long th = 0;
  vector<long long> ths = {0};
  for (int i = 1; i < log(MAX_N) / log(M) + 1; i++) {
    th += pow(M, i);
    ths.push_back(th);
    if (N <= th)
      j = min(j, i);
  }

  // cout << "length: " << j << endl;

  string ans = "";
  N -= 1;
  for (; j > 0; j--) {
    int x = (N - ths[j - 1]) / pow(M, j - 1);
    N -= (x + 1) * pow(M, j - 1);
    cout << alphabets[x];
  }

  cout << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <cassert>
#include <cmath>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
using namespace std;

int main() {
  long long N;
  cin >> N;
  assert(N >= 1);

  const string alphabets = "abcdefghijklmnopqrstuvwxyz";
  const long long MAX_N = 1000000000000001;
  const int M = 26;

  int j = 1000000000;
  long long th = 0;
  vector<long long> ths = {0};
  for (int i = 1; i < log(MAX_N) / log(M); i++) {
    th += pow(M, i);
    ths.push_back(th);
    if (N <= th)
      j = min(j, i);
  }

  // cout << "length: " << j << endl;

  string ans = "";
  N -= 1;
  for (; j > 0; j--) {
    int x = (N - ths[j - 1]) / pow(M, j - 1);
    N -= (x + 1) * pow(M, j - 1);
    cout << alphabets[x];
  }

  cout << endl;

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

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

int main() {
  long long N, i = 0;
  cin >> N;
  if (N == 0)
    return 0;
  vector<char> name(26);
  vector<char> na;
  char m;
  for (m = 'a'; m <= 'z'; ++m) {
    name.at(i) = m;
    i++;
  }
  int s, j = 0;
  while (N > 26) {
    s = N % 26;
    if (s > 0)
      na.push_back(name.at(s - 1));
    else {
      na.push_back(name.at(25));
      N--;
    }
    j++;
    N = N / 26;
  }
  if (N > 0)
    na.push_back(name.at(N - 1));
  else
    na.push_back(name.at(25));

  reverse(na.begin(), na.end());
  for (int k = 0; k < na.size(); k++) {
    cout << na.at(k);
  }
  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  int N, i = 0;
  cin >> N;
  vector<char> name(26);
  vector<char> na;
  char m;
  for (m = 'a'; m <= 'z'; ++m) {
    name.at(i) = m;
    i++;
  }
  int s, j = 0;
  while (N > 26) {
    s = N % 26;
    na.push_back(name.at(s - 1));
    j++;
    N = N / 26;
  }
  if (N > 0) {
    na.push_back(name.at(N - 1));
    j++;
  }
  reverse(na.begin(), na.end());
  for (int k = 0; k < j; k++) {
    cout << na.at(k);
  }
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long N;
  long long B;
  string S = "abcdefghijklmnopqrstuvwxyz";
  string A = "";
  cin >> N;
  int count = 0;
  while (N > 0) {
    B = N % 26 - 1;
    if (B == -1)
      B = 25;
    N = (N - 1) / 26;
    A += S.at(B);
    count++;
    // cout << "B=" << B << "N=" << N << endl;
  }
  reverse(A.begin(), A.end());
  cout << A << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  long long N;
  int B;
  string S = "abcdefghijklmnopqustuvwxyz";
  vector<int> V(100, -1);
  cin >> N;
  int count = 0;
  while (N > 0) {
    B = N % 26 - 1;
    N = (N - 1) / 26;
    V.at(count) = B;
    count++;
  }
  if (count >= 2) {
    for (int i = 0; i < count; i++) {
      cout << S.at(V.at(count - i - 1));
    }
  } else {
    cout << S.at(V.at(0));
  }
  cout << endl;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

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

namespace ABC171 {
class C {
public:
  C() = default;
  ~C() = default;

  void Run() {
    long long N;
    std::cin >> N;

    constexpr int KIND_ALPHA = 26;

    std::string str = {};

    int count = 1;
    long long m = KIND_ALPHA;
    long long accum = KIND_ALPHA;
    while (accum < N) {
      count++;
      m *= KIND_ALPHA;
      accum += m;
    }

    long long val = N - 1;
    for (int i = 0; i < count; ++i) {
      char buf[2] = {static_cast<char>('a' + (val % KIND_ALPHA)), '\\0'};
      str += buf;
      val = (val / KIND_ALPHA) - 1;
    }
    std::reverse(str.begin(), str.end());

    std::cout << str << std::endl;
  }
};
} // namespace ABC171

int main() {

  ABC171::C prob;
  prob.Run();

  return 0;
}

Error: TLE

Fixed submission:

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

namespace ABC171 {
class C {
public:
  C() = default;
  ~C() = default;

  void Run() {
    long long N;
    std::cin >> N;

    constexpr int KIND_ALPHA = 26;

    std::string str = {};

    int count = 1;
    int m = KIND_ALPHA;
    int accum = KIND_ALPHA;
    while (accum < N) {
      count++;
      m *= KIND_ALPHA;
      accum += m;
    }

    long long val = N - 1;
    for (int i = 0; i < count; ++i) {
      char buf[2] = {static_cast<char>('a' + (val % KIND_ALPHA)), '\\0'};
      str += buf;
      val = (val / KIND_ALPHA) - 1;
    }
    std::reverse(str.begin(), str.end());

    std::cout << str << std::endl;
  }
};
} // namespace ABC171
int main() {

  ABC171::C prob;
  prob.Run();

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  ll x;
  cin >> x;
  ll occ = 1;
  ll interval = 26;
  deque<char> dq;
  while (x > 0) {
    ll r = (x - 1) % interval + 1;
    r = (r - 1) / occ;

    dq.push_front('a' + r);

    x = x - interval;
    interval = interval * 26;
    occ = occ * 26;
  }

  string s;
  while (!dq.empty()) {
    s.push_back(dq.front());
    dq.pop_front();
  }

  cout << s << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

  ll sum = 0;
  unordered_map<ll, ll> m;
  for (ll i = 0; i < n; i++) {
    ll x;
    cin >> x;

    m[x]++;
    sum = sum + x;
  }

  ll q;
  cin >> q;

  for (ll i = 0; i < q; i++) {
    ll b, c;
    cin >> b >> c;

    sum = sum - m[b] * b;
    sum = sum + m[b] * c;
    m[c] = m[c] + m[b];
    m[b] = 0;

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

#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "ctime"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main() {
  ll N;
  cin >> N;
  ll c = 26, digit = 1;
  while (N - c > 0) {
    N -= c;
    c *= 26;
    digit++;
  }

  // 0-indexed
  N--;

  vector<ll> ans(digit, 0);
  rep(0, i, digit) {
    ans.at(i) = N % 26;
    N /= 26;
  }
  reverse(all(ans));

  rep(0, i, digit) { cout << (char)('a' + ans.at(i)); }
  cout << endl;
}


Error: 0

Fixed submission:

#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "ctime"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main() {
  ll N;
  cin >> N;
  vector<ll> num;
  ll c = 1;
  while (c <= 1000000000000001) {
    num.push_back(c);
    c *= 26;
  }

  reverse(all(num));
  vector<ll> ans(num.size());

  ll count = 0;
  for (auto n : num) {
    if (N % n == 0 && n != 1) {
      while (count < num.size()) {
        count++;
        if (count == num.size() - 1) {
          ans.at(count) = 26;
        } else {
          ans.at(count) = 25;
        }
        count++;
      }
      rep(0, i, num.size()) {
        if ((ans.at(i) == 25) || (ans.at(i) == 26)) {
          cout << (char)('a' + ans.at(i) - 1);
        }
      }
      return 0;
    }
    ans.at(count) = N / n;
    N %= n;
    count++;
  }
  rep(0, i, num.size()) {
    if (ans.at(i) == 0) {
      continue;
    } else {
      cout << (char)('a' + ans.at(i) - 1);
    }
  }

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

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

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

  vector<long long> s(13);
  s.at(0) = 1;
  for (int i = 1; i < 12; i++) {
    s.at(i) = s.at(i - 1) + pow(26, i);
  }

  int k = 1;
  for (int i = 0; i < 12; i++) {
    if (s.at(i) <= N && N < s.at(i + 1)) {
      k = i + 1; // k文字の名前
      break;
    }
  }

  long long l = N - s.at(k - 1) + 1; // k文字の名前のうち辞書順でl番目

  vector<char> answer(k);
  if (k != 1) {
    for (int i = 0; i < k - 1; i++) {
      long long jou = pow(26, k - i - 1);
      int number = l / jou;
      if (l % jou == 0)
        number -= 1;
      else if (l % 26 == 0 && l / 26 < 26)
        number = l / 26;
      answer.at(i) = 'a' + number;
      l -= number * pow(26, k - i - 1);
    }
  }
  if (l == 0)
    answer.at(k - 1) = 'z';
  else
    answer.at(k - 1) = 'a' + l - 1;
  for (int i = 0; i < k; i++)
    cout << answer.at(i);
}

Error: WA

Fixed submission:

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

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

  vector<long long> wa(13);
  wa.at(0) = 1;
  for (int i = 1; i < 12; i++) {
    wa.at(i) = wa.at(i - 1) + pow(26, i);
  }

  int k = 1;
  for (int i = 0; i < 12; i++) {
    if (wa.at(i) <= N && N < wa.at(i + 1)) {
      k = i + 1; // k文字の名前
      break;
    }
  }

  long long l = N - wa.at(k - 1) + 1; // k文字の名前のうち辞書順でl番目

  string alphabet = "abcdefghijklmnopqrstuvwxyz";
  vector<char> answer(k);
  if (k != 1) {
    for (int i = 0; i < k - 1; i++) {
      int number = l / pow(26, k - i - 1);
      answer.at(i) = alphabet.at(number);
      l -= number * pow(26, k - i - 1);
    }
  }
  if (l == 0)
    answer.at(k - 1) = 'z';
  else
    answer.at(k - 1) = alphabet.at(l - 1);
  for (int i = 0; i < k; i++)
    cout << answer.at(i);
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
  ll n;
  cin >> n;
  string s;
  while (n > 0) {
    ll k = (n - 1) % 26;
    s += char(k + 'a');
    n = (n - 1) / 26;
  }
  reverse(all(s));
  cout << s;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
  ll n;
  cin >> n;
  string s;
  while (1) {
    ll k = (n - 1) % 26;
    s += char(k + 'a');
    n = n / 26;
  }
  reverse(all(s));
  cout << s;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  unsigned long long n;
  cin >> n;
  vector<int> p;
  while (n > 0) {
    n--;
    p.push_back((n + 1) % 26);
    n /= 26;
  }
  reverse(p.begin(), p.end());
  for (int y : p)
    cout << char((y ? y : 26) - 1 + 'a');
  cout << '\\n';
}


Error: 0

Fixed submission:

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

int main() {
  unsigned long long n;
  cin >> n;
  vector<int> p;
  n--;
  while (n > 0) {
    p.push_back(n % 26);
    n /= 26;
  }
  p[0]++;
  reverse(p.begin(), p.end());
  for (int y : p)
    cout << char((y ? y : 26) - 1 + 'a');
  cout << '\\n';
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long int n;
  cin >> n;
  n -= 1;

  vector<int> ans;
  while (n >= 0) {
    ans.push_back(n % 26LL);
    n -= (n % 26LL) + 26;
    n /= 26LL;
  }
  reverse(ans.begin(), ans.end());
  int l = ans.size();
  for (int i = 0; i < l; i++) {
    cout << (char)('a' + ans[i]);
  }
  cout << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  long long int n;
  cin >> n;
  n -= 1;

  vector<int> ans;
  while (n > 0) {
    ans.push_back(n % 26LL);
    n /= 26LL;
  }
  reverse(ans.begin(), ans.end());
  int l = ans.size();
  for (int i = 0; i < l - 1; i++) {
    cout << (char)('a' + ans[i] - 1);
  }
  cout << (char)('a' + ans[l - 1]) << endl;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  string s = "";
  while (n > 0) {
    n--;
    s += ('a' + (n % 26));
    n /= 26;
  }
  reverse(s.begin(), s.end());
  cout << s;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s = "";
  while (n >= 0) {
    n--;
    s += ('a' + (n % 26));
    n /= 26;
  }
  reverse(s.begin(), s.end());
  cout << s;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9 + 7;

// 繰り返し二乗法
ll EX(ll x, ll n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 1)
    return EX(x, n - 1) * x;
  else
    return EX(x * x, n / 2);
};

vector<int> ac(ll n, int k) {
  vector<int> res;
  while (n > 0) {
    if (n % 26 == 0) {
      res.push_back(26);
      n = (n - 1) / 26;
    } else {
      res.push_back(n % 26);
      n /= 26;
    }
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector<int> num = ac(n, 26);
  for (int i = num.size() - 1; i >= 0; i--) {
    cout << (char)('a' + num[i] - 1);
  }
  cout << endl;
  return 0;
}

Error: -8

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9 + 7;

// 繰り返し二乗法
ll EX(ll x, ll n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 1)
    return EX(x, n - 1) * x;
  else
    return EX(x * x, n / 2);
};

ll calc(int n) {
  ll res = 0;
  for (int i = 1; i <= n; i++) {
    res += EX(26, i);
  }
  return res;
}

ll n;
vector<char> ans;
void solve(ll p, ll size, ll n) {
  if (size == 0)
    return;
  ll s = (n - p) / EX(26, size - 1);
  char al = 'a' + (s - 1);
  ans.push_back(al);
  solve(p + s * EX(26, size - 1), size - 1, n);
}

int main() {

  cin >> n;
  int size;
  for (int i = 0; i < 12; i++) {
    if (calc(i) < n && n <= calc(i) * 26) {
      size = i + 1;
      break;
    }
  }
  cout << size << endl;
  solve(0, size, n);
  for (auto p : ans)
    cout << p;
  cout << endl;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

long long power(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);

#ifndef ONLINE_JUDGE
  if (fopen("INPUT.txt", "r")) {
    freopen("INPUT.txt", "r", stdin);
    freopen("OUTPUT.txt", "w", stdout);
  }
#endif

  int n;
  cin >> n;
  int ini = 1;
  int z = 1;
  while (1) {
    z *= 26;
    if (z < n)
      n -= z;
    else
      break;
    ini++;
  }

  vector<int> ans;
  for (int i = 1; i <= ini && n > 0; i++) {
    for (int j = 0; j < 26; j++) {
      int z = power(26, ini - i) * (j + 1);
      if (z > n) {
        n -= power(26, ini - i) * j;
        ans.push_back(j);
        break;
      } else if (z == n) {
        ans.push_back(j);
        for (int j = i + 1; j <= ini; j++)
          ans.push_back(25);
        n = -1;
        break;
      }
    }
  }

  for (auto i : ans)
    cout << char(97 + i);
  cout << '\\n';
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

long long power(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);

#ifndef ONLINE_JUDGE
  if (fopen("INPUT.txt", "r")) {
    freopen("INPUT.txt", "r", stdin);
    freopen("OUTPUT.txt", "w", stdout);
  }
#endif

  int n;
  cin >> n;
  int ini = 1;
  int z = 1;
  while (1) {
    z *= 26;
    // int z=power(26,ini);
    if (z < n)
      n -= z;
    else
      break;
    ini++;
  }
  // cout<<power(26,13)<<'\\n';
  vector<int> ans;
  for (int i = 1; i <= ini && n > 0; i++) {
    for (int j = 0; j < 26; j++) {
      int z = power(26, ini - i) * (j + 1);
      if (z > n) {
        n -= power(26, ini - i) * j;
        ans.push_back(j);
        break;
      } else if (z == n) {
        ans.push_back(j);
        for (int j = i + 1; j <= ini; i++)
          ans.push_back(25);
        n = -1;
        break;
      }
    }
  }

  for (auto i : ans)
    cout << char(97 + i);
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define PER(i, a, b) for (ll i = (a); i >= (b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a) (a).begin(), (a).end()
const ll INF = 1e18 + 18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;

int main() {
  ll N;
  cin >> N;
  ll Key = 26;
  ll Keta = 1;
  while (Key < N) {
    N -= Key;
    Key *= 26;
    Keta++;
  }
  string S = "abcdefghijklmnopqrstuvwxyz";
  // cout<<N<<endl;
  // cout<<Key/26<<endl;
  Key /= 26;
  if (N == 0) {
    rep(i, Keta - 1) { cout << 'z'; }
    return 0;
  }
  N--;
  rep(i, Keta) {
    ll J = N / Key;
    N %= Key;
    cout << S.at(J);
    Key /= 26;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define PER(i, a, b) for (ll i = (a); i >= (b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a) (a).begin(), (a).end()
const ll INF = 1e18 + 18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;

int main() {
  ll N;
  cin >> N;
  ll Key = 26;
  ll Keta = 1;
  while (Key < N) {
    N -= Key;
    Key *= 26;
    Keta++;
  }
  string S = "abcdefghijklmnopqrstuvwxyz";
  // cout<<N<<endl;
  // cout<<Key/26<<endl;
  Key /= 26;
  if (N == 0) {
    rep(i, Keta - 1) { cout << 'z'; }
    return 0;
  }
  rep(i, Keta) {
    ll J = N / Key;
    N %= Key;
    if (i < Keta - 1)
      cout << S.at(J);
    if (i == Keta - 1)
      cout << S.at(J - 1);
    Key /= 26;
  }
  cout << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  list<char> s;
  cin >> n;
  while (n) {
    n--;
    s.push_front('a' + n % 26);
    n /= 26;
  }
  string ss(s.begin(), s.end());
  cout << ss << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ull n, start = 1, end = 26, c = 1, pow = 26, diff;
  string s = "";
  cin >> n;
  while (end < n) {
    c++;
    pow *= 26;
    start = end + 1;
    end = (pow)-1 + start;
  }
  while (c > 0) {
    s += 'a';
    c--;
  }
  c = s.size();
  diff = n - start;
  ull j = c - 2, k = c - 2;
  while (diff != 0) {
    if (diff < 26) {
      while (diff > 0) {
        if (s[c - 1] != 'z')
          s[c - 1] += 1;
        else {
          while (true) {
            if (s[j] != 'z') {
              s[j] += 1;
              break;
            } else {
              s[j] = 'a';
              j--;
            }
          }
          j = c - 2;
        }
        diff -= 1;
      }
    } else {
      if (s[k] != 'z') {
        s[k] += 1;
      } else {
        while (true) {
          if (s[j] != 'z') {
            s[j] += 1;
            break;
          } else {
            s[j] = 'a';
            j--;
          }
        }
        j = c - 2;
      }
      diff -= 26;
    }
  }
  cout << s;
}