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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

#define int long long int
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9 + 7;

template <typename T> using vector2 = vector<vector<T>>;
template <typename T> vector2<T> initVec2(size_t n0, size_t n1, T e = T()) {
  return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T> using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()) {
  return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

  int n;
  cin >> n;

  int s = 26;
  int t = 26;
  int cnt = 1;

  while (s < n) {
    t *= 26;
    s += t;
    cnt++;
  }
  n -= s - t + 1;

  stack<int> ans;
  while (cnt > 0) {
    ans.push(n % 26);
    n /= 26;
    cnt--;
  }

  while (not ans.empty()) {
    int x = ans.top();
    ans.pop();
    cout << char('a' + x);
  }
  cout << endl;

  return 0;
}


Error: -8

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

#define int long long int
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9 + 7;

template <typename T> using vector2 = vector<vector<T>>;
template <typename T> vector2<T> initVec2(size_t n0, size_t n1, T e = T()) {
  return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T> using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()) {
  return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

  int n;
  cin >> n;

  int s = 26;
  int t = 26;

  while (s < n) {
    t *= 26;
    s += t;
  }

  vector<int> ans;
  while (n != 0) {
    t /= 26;
    int x = n / t;
    if (n % t == 0) {
      x--;
    }
    ans.push_back(x);
    n -= x * t;
  }

  for (int x : ans) {
    cout << char('a' + x - 1);
  }
  cout << endl;

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

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

int main() {
  ll n = 0;
  cin >> n;
  int count = 1;
  ll a, b = 0;
  a = 26;
  while (a < n || n <= b) {
    b = a;
    a = (a + 1) * 26;
    count++;
  }
  ll m = n - b - 1;
  vector<char> v(count);
  int ch = 0;
  ll dummy;
  string alphabet = "abcdefghijklmnopqrstuvwxyz";
  rep(i, count) {
    dummy = pow(26, count - i - 1);
    ch = m / dummy;
    m = m % dummy;
    v[i] = alphabet[ch];
  }
  rep(i, count) cout << v[i];
  cout << endl;
}

Error: 0

Fixed submission:

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

int main() {
  ll n = 0;
  cin >> n;
  int count = 1;
  int m = n;
  while (m > 26) {
    m /= 26;
    count++;
  }
  vector<char> a(count);
  int ch = 0;
  int dummy;
  string alphabet = "aabcdefghijklmnopqrstuvwxyz";
  rep(i, count) {
    dummy = pow(26, count - i - 1);
    ch = n / dummy;
    n = n % dummy;
    a[i] = alphabet[ch];
  }
  rep(i, count) cout << a[i];
  cout << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for (int(i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\\n"
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T> auto compare = [](T x, T y) -> bool { return (x < y); };
const int MOD = 1000000007;

signed main() {
  ll N, k = 1;
  vector<ll> v;
  cin >> N;
  if (N == 1) {
    PRINT("a");
    return 0;
  } else if (N == 2) {
    PRINT("b");
    return 0;
  }
  ll n = N;
  while (n > 0) {
    v.push_back((n - 1) / k % 26);
    k *= 26;
    n -= k;
  }
  for (int i = v.size() - 1; i >= 0; i--) {
    char c;
    c = 'a' + v[i];
    cout << c;
  }
  cout << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for (int(i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\\n"
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T> auto compare = [](T x, T y) -> bool { return (x < y); };
const int MOD = 1000000007;

ll N, Q;
ll A[100010];
map<ll, ll> mp;

signed main() {
  cin >> N;
  ll ans = 0;
  REP(i, N) {
    cin >> A[i];
    mp[A[i]]++;
    ans += A[i];
  }
  cin >> Q;
  ll B, C;
  REP(i, Q) {
    cin >> B >> C;
    ans += (C - B) * mp[B];
    mp[C] += mp[B];
    mp[B] = 0;
    PRINT(ans);
  }
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

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

LL power(int a, int x) {
  LL res = 1;
  while (x) {
    if (a & 1)
      res *= a;
    a *= a, x /= 2;
  }
  return res;
}

int main() {
  LL range[12] = {};
  for (int i = 1; i < 12; i++) {
    range[i] = range[i - 1] + power(26, i);
  }
  LL n, i;
  cin >> n;

  for (i = 1; i < 12; i++) {
    if (n / range[i] < 1)
      break;
  }
  string ans = "";
  for (LL j = i - 1; j >= 0 and n > 0; j--) {
    n--;
    char c = 'a' + n % 26;
    n /= 26;
    ans += c;
  }
  reverse(ans.begin(), ans.end());
  cout << ans;
}

Error: TLE

Fixed submission:

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

LL power(int a, int x) {
  LL res = 1;
  while (a) {
    if (a & 1)
      res *= a;
    a *= a, x /= 2;
  }
  return res;
}

int main() {
  LL range[12] = {};
  for (int i = 1; i < 12; i++) {
    range[i] = range[i - 1] + power(26, i);
  }
  LL n, i;
  cin >> n;

  for (i = 1; i < 12; i++) {
    if (n / range[i] < 1)
      break;
  }
  string ans = "";
  for (LL j = i - 1; j >= 0 and n > 0; j--) {
    char c = 'a' - 1 + n % 26;
    n /= 26;
    ans += c;
  }
  reverse(ans.begin(), ans.end());
  cout << ans;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i, a, n) for (ll i = a; i <= n; i++)
#define f_(i, a, n) for (ll i = a; i >= n; i--)
char ita(int i) { return static_cast<char>('a' + i); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, m, j = 1, count = 0;
  cin >> n;
  m = n - 1;
  if (n == 1)
    cout << 'a' << endl;
  else {
    while (m > 0) {
      j = j * 26;
      count++;
      if (m == j) {
        f(i, 0, count) cout << 'a';
        break;
      }
      if (m / j > 0) {
        m = m - j;
      } else {
        n = m;
        m = 0;
      }
    }
    if (m != 0) {
      cout << endl;
      return 0;
    }
    m = n;
    j = j / 26;
    ll k = 0;
    while (j > 1) {
      k = m / j;
      m = m % j;
      cout << ita(k);
      j = j / 26;
    }
    cout << ita(m) << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i, a, n) for (ll i = a; i <= n; i++)
#define f_(i, a, n) for (ll i = a; i >= n; i--)
char ita(int i) { return static_cast<char>('a' + i); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  while (1) {
    ll n, m, j = 1;
    cin >> n;
    m = n - 1;
    if (n == 1)
      cout << 'a' << endl;
    else {
      while (m > 0) {
        j = j * 26;
        if (m / j > 0) {
          m = m - j;
        } else {
          n = m;
          m = 0;
        }
      }
      m = n;
      j = j / 26;
      ll k = 0;
      while (j > 1) {
        k = m / j;
        m = m % j;
        cout << ita(k);
        j = j / 26;
      }
      cout << ita(m) << endl;
    }
  }
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1000000000;

int main() {
  ll N;
  cin >> N;
  string alphabets = "abcdefghijklmnopqrstuvwxyz";
  string ans;

  while (N > 26) {
    if (N % 26 - 1 < 0)
      ans += "z";
    else
      ans += alphabets[(N - 1) % 26];
    N -= (N - 1) % 26;
    N /= 26;
  }
  ans += alphabets[(N - 1) % 26];
  reverse(all(ans));
  cout << ans << endl;
}


Error: 0

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1000000000;

int main() {
  ll N;
  cin >> N;
  string alphabets = "abcdefghijklmnopqrstuvwxyz";
  string ans;
  while (N > 26) {
    ans += alphabets[N % 26 - 1];
    N /= 26;
  }
  ans += alphabets[N - 1];
  reverse(all(ans));
  cout << ans << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

using namespace std;
typedef long long int ll;
const ll INF = 1000000000000000000;
const double PI = acos(-1);

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

Error: -11

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

using namespace std;
typedef long long int ll;
const ll INF = 1000000000000000000;
const double PI = acos(-1);

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

  ll bound = 0;
  ll num = 0;
  for (int i = 1; i <= 11; i++) {
    ll pow_num = 1;
    rep(j, i) pow_num *= 26;
    bound += pow_num;
    if (bound >= n) {
      num = i;
      break;
    }
  }
  cout << num << endl;
  vector<int> p(num + 1);
  for (int i = num; i >= 0; i--) {
    ll pow_num = 1;
    rep(j, i) pow_num *= 26;
    if (n >= pow_num) {
      p[i] = n / pow_num;
      n %= pow_num;
    }
  }
  rep(i, num + 1) { cout << p[i] << endl; }
  string ans;
  if (p[num] == 1) {
    if (p[num - 1] == 1) {
      rep(i, num) { ans += 'z'; }
      cout << ans << endl;
      return 0;
    }
    bool ok = true;
    for (int i = num - 1; i >= 0; i--) {
      if (p[i] != 0)
        ok = false;
    }
    if (ok) {
      rep(i, n) { ans += 'y'; }
      cout << ans << endl;
      return 0;
    }
    for (int i = num - 2; i > 0; i--) {
      char tmp = 'a';
      ans += (char)(tmp + p[i]);
    }
    char tmp2 = 'a';
    if (p[0] == 0) {
      ans += 'z';
    } else {
      ans += (char)(tmp2 + p[0] - 1);
    }
  } else {
    for (int i = num - 1; i >= 0; i++) {
      char tmp = 'a';
      ans += (char)(tmp + p[i] - 1);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long n;
string a, b;
char c;
int main() {
  cin >> n;
  do {
    c = (n - 1) % 26 + 'a';
    a += c;
    n = (n - 1) / 26;
  } while (n > 0);
  for (int i = a.size() - 1; i >= 0; i--)
    b += a[i];
  cout << b;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  char a[27] = {'!', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
                'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
                'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  bool f = 0;
  cin >> n;
  while (n != 0) {
    if (n > 26) {
      if (n % 26 > 0)
        cout << a[n / 26];
      else {
        cout << a[n / 26 - 1];
        n = 26;
        f = 1;
      }
      if (f == 1) {
        f = 0;
        break;
      }
      n = n % 26;
    }
    if (n < 27 && n > 0) {
      cout << a[n];
      return 0;
    }
  }
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

long long n;
string ans;

int main() {
  scanf("%lld", &n);
  while (n) {
    n--;
    ans += 'a' + n % 26;
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

long long n, t = 1;
bool flag;
string ans;
string alpha[30] = {"z", "a", "b", "c", "d", "e", "f", "g", "h",
                    "i", "j", "k", "l", "m", "n", "o", "p", "q",
                    "r", "s", "t", "u", "v", "w", "x", "y"};

int main() {
  scanf("%lld", &n);
  while (t <= n) {
    int m;
    m = n / t % 26;
    if (flag)
      m--, flag = false;
    if (m == 0)
      flag = true;
    ans += alpha[m];
    t *= 26;
  }
  if (ans[ans.size() - 1] == 'z')
    ans.erase(ans.size() - 1, 1);
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main() {

  long long N;
  cin >> N;
  N--;

  string alp = "abcdefghijklmnopqrstuvwxyz";

  long long ival = 0;
  long long dval = 26;
  long long fval = 25;
  while (N > fval) {
    dval *= 26;
    fval += dval;
    ival += 1;
  }

  string ans = "";

  long long ind;
  N -= fval / 26;
  for (long long i = ival; i >= 0; i--) {
    ind = N / pow(26, i);
    N -= ind * pow(26, i);
    ans += alp.substr(ind, 1);
  }

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main() {

  long long N;
  cin >> N;
  N--;

  string alp = "abcdefghijklmnopqrstuvwxyz";

  long long ival = 0;
  long long dval = 26;
  long long fval = 25;
  while (N > fval) {
    dval *= 26;
    fval += dval;
    ival += 1;
  }

  if (N == fval) {
    ival += 1;
  }

  string ans = "";

  long long ind;

  for (long long i = ival; i >= 0; i--) {
    ind = N / pow(26, i);
    N -= ind * pow(26, i);
    if (i != 0) {
      ind--;
    }
    ans += alp.substr(ind, 1);
  }

  cout << ans << endl;

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

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

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

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

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define _LIBCPP_DEBUG 0
#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;
  int l = 1, m = 0, x;
  if (n <= 26)
    x = 1;
  if (n >= 27 && n <= 702)
    x = 2;

  vector<char> A(27);
  vector<ll> name;
  vector<char> ans;
  A[0] = 'A';
  for (char i = 'a'; i <= 'z'; i++) {
    A[l] = i;
    l++;
  }

  while (n >= 27) {
    name[m] = n % 26;
    n /= 26;
    m++;
  }
  name[m] = n;
  reverse(name.begin(), name.end());

  for (int i = 0; i < name.size(); i++) {
    if (name[i] != 0)
      ans[i] = A[name[i]];
    if (ans[i] == 'A')
      ans.erase(ans.begin() + i);
  }

  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

string GetName(ll num, ll index) {
  string ret;
  for (ll i = 0; i < num; i++) {
    int temp = index % 26;
    ret += char('a' + temp);
    index /= 26;
  }
  std::reverse(ret.begin(), ret.end());
  return ret;
}

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

  ll num = 1;
  ll cur = 1;
  while (cur <= N) {
    cur += pow(26, num);
    ++num;
  }
  --num;
  cur -= pow(26, num);

  ll target = N - cur;
  string ret = GetName(num, target);
  cout << ret << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

string GetName(int num, int index) {
  string ret;
  for (int i = 0; i < num; i++) {
    int temp = index % 26;
    ret += char('a' + temp);
    index /= 26;
  }
  std::reverse(ret.begin(), ret.end());
  return ret;
}

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

  int num = 1;
  int cur = 1;
  while (cur <= N) {
    cur += pow(26, num);
    ++num;
  }
  --num;
  cur -= pow(26, num);

  int target = N - cur;
  string ret = GetName(num, target);
  cout << ret << endl;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip> //setprecision()
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using ll = long long;
using namespace std;

double Mcos(double k) { return cos(k * atan(1.0) * 4 / 180); }

void monmo() {}

int main() {
  ll n;
  string name = "abcdefghijklmnopqrstuvwxyz";
  string ans = "";
  cin >> n;
  while (n > 0) {
    n--;
    ans += name[n % 26];
    n /= 26;
  }

  for (int i = ans.size() - 1; i >= 0; i--) {
    cout << ans[i];
  }
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip> //setprecision()
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using ll = long long;
using namespace std;

double Mcos(double k) { return cos(k * atan(1.0) * 4 / 180); }

void monmo() {}

int main() {
  ll n, num, p, tmp = 0;
  string name = "zabcdefghijklmnopqrstuvwxyz";
  cin >> n;
  int i;

  for (i = 1;; i++) {
    num = pow(26, i) + tmp;
    tmp = num;
    if (n <= num)
      break;
  }
  int r = i - 1; // 桁数

  for (int i = r; i > 0; i--) {
    num = pow(26, i);
    p = (n - pow(26, i)) / num;
    if (p >= 26)
      p = 26;
    cout << name[p];
    n -= p * pow(26, i);
  }
  cout << name[n];
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>

int main() {
  long n;
  std::cin >> n;
  std::string text;

  long value = 0;
  int max;
  for (max = 1;; ++max) {
    value += std::pow(26, max);

    if (value >= n) {
      // std::cout << value << std::endl;
      break;
    }
  }

  for (int i = max; i >= 1; --i) {
    long pog = std::pow(26, i - 1);
    for (int j = 25;; j--) {
      if (value - pog < n) {
        text += char(0x61 + j);

        break;
      } else
        value -= pog;
    }
  }
  std::cout << text << std::endl;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

int main() {
  long n;
  std::cin >> n;
  std::string text;

  int value;
  int max;
  for (max = 1;; ++max) {
    value = 0;
    for (int i = 1; i <= max; ++i) {
      value += 26 * std::pow(26, i - 1);
    }

    if (value >= n) {
      // std::cout << value << std::endl;
      break;
    }
  }

  for (int i = max; i >= 1; --i) {
    for (int j = 25;; j--) {
      if (value - std::pow(26, i - 1) < n) {
        text += char(0x61 + j);

        break;
      } else
        value -= std::pow(26, i - 1);
    }
  }
  std::cout << text << std::endl;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll N;
  cin >> N;
  int size = 1;
  ll now = 0;
  while (1) {
    ll k = pow(26, size);
    now += k;
    if (now >= N)
      break;
    size++;
  }

  now -= pow(26, size);
  ll kouho = N - now;
  kouho--;
  vector<int> A(size);
  rep(i, size) {
    int x = kouho % 26;
    A[i] = x;
    kouho /= 26;
  }

  char S[size];
  rep(i, size) { S[i] = 'a'; }

  for (int i = 0; i < size; i++) {
    S[i] += A[size - 1 - i];
  }

  rep(i, size) {
    cout << S[i];
    if (i == size - 1) {
      cout << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ll N;
  cin >> N;
  int size = 1;
  int now = 0;
  while (1) {
    int k = pow(26, size);
    now += k;
    if (now >= N)
      break;
    size++;
  }

  now -= pow(26, size);
  int kouho = N - now;
  kouho--;
  vector<int> A(size);
  rep(i, size) {
    int x = kouho % 26;
    A[i] = x;
    kouho /= 26;
  }

  char S[size];
  rep(i, size) { S[i] = 'a'; }

  for (int i = 0; i < size; i++) {
    S[i] += A[size - 1 - i];
  }

  rep(i, size) {
    cout << S[i];
    if (i == size - 1) {
      cout << endl;
    }
  }

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

#include <iostream>
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  string s = "";
  while (n) {
    n--;
    // cout << n << endl;
    char c = n % 26 + 'a';
    // cout << n << " % 26 = " << c << endl;
    s = c + s;
    n /= 26;
  }
  cout << s << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

LL f[20];

LL p[20];

int main() {
  LL n;
  scanf("%lld", &n);

  f[0] = 1;
  for (int i = 1; i <= 10; ++i)
    f[i] = 26ll * f[i - 1];
  for (int i = 2; i <= 10; ++i)
    f[i] += f[i - 1];

  p[0] = 1;
  for (int i = 1; i <= 10; ++i)
    p[i] = 26ll * p[i - 1];

  int idx = 1;
  while (f[idx] < n)
    ++idx;

  string res;

  LL cnt;
  if (idx == 1)
    cnt = 0;
  else
    cnt = f[idx - 1];

  for (int i = 1; i <= idx; ++i) {
    for (int ch = 0; ch <= 25; ++ch) {
      LL t = cnt + 1ll * (ch + 1) * p[idx - i];
      if (t >= n) {
        res += ch + 'a';
        cnt += 1ll * ch * p[idx - i];
        break;
      }
    }
  }

  cout << res;

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

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

int main() {
  long long N, a = 26, k = 1;
  cin >> N;
  while (N > a) {
    N -= a;
    a *= 26;
    k++;
  }
  N--;
  for (int i = 0; i < k; i++) {
    a /= 26;
    int b = N / a;
    cout << (char)('a' + b);
    N %= a;
  }
  cout << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int a = 26, k = 1;
  long long N;
  cin >> N;
  while (N > a) {
    N -= a;
    a *= 26;
    k++;
  }
  N--;
  for (int i = 0; i < k; i++) {
    a /= 26;
    int b = N / a;
    cout << (char)('a' + b);
    N %= a;
  }
  cout << endl;
}