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

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

int main() {
  long long N;
  cin >> N;
  string res = "";
  while (N) {
    --N;
    res += (char)('a' + (N % 26));
    N /= 26;
  }
  reverse(res.begin(), res.end());
  cout << res << endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;           // 10^19 < 9223372036854775807
typedef unsigned long long ull; // 10^20 < 18446744073709551615

int main() {
  ll n;
  cin >> n;
  string ans = "";
  map<int, string> score; // 名前→成績
  score[1] = "a";
  score[2] = "b";
  score[3] = "c";
  score[4] = "d";
  score[5] = "e";
  score[6] = "f";
  score[7] = "g";
  score[8] = "h";
  score[9] = "i";
  score[10] = "j";
  score[11] = "k";
  score[12] = "l";
  score[13] = "m";
  score[14] = "n";
  score[15] = "o";
  score[16] = "p";
  score[17] = "q";
  score[18] = "r";
  score[19] = "l";
  score[20] = "s";
  score[21] = "u";
  score[22] = "v";
  score[23] = "w";
  score[24] = "x";
  score[25] = "y";
  score[26] = "z";

  while (n >= 1) {
    int i = n % 26;
    // cout << i;
    ans.insert(0, score.at(i));
    n /= 26;
    // cout<<n;
  }
  cout << ans;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int64_t N;
  cin >> N;
  int P = N / 26;
  vector<char> namae(100);
  int i = 0;
  // cout << N << " " << i << endl ;

  while (N != 0) {
    N--;
    int M = N % 26;
    namae.at(i) = 'a' + M;
    N /= 26;
    i++;

    // cout << N << " " << i << endl ;
  }

  for (int j = i - 1; j >= 0; j--) {
    cout << namae.at(j);
  }
}

Error: WA

Fixed submission:

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

int main() {
  int64_t N;
  cin >> N;
  int64_t P = N / 26;
  vector<char> namae(P + 1);
  int64_t i = 0;
  // cout << N << " " << i << endl ;

  while (N != 0) {
    N--;
    int M = N % 26;
    namae.at(i) = 'a' + M;
    N /= 26;
    i++;

    // cout << N << " " << i << endl ;
  }

  for (int j = i - 1; j >= 0; j--) {
    cout << namae.at(j);
  }
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

char nth_letter(int64_t n) {
  assert(n >= 0 && n <= 25);
  return "abcdefghijklmnopqrstuvwxyz"[n];
}

int main() {
  int64_t N;
  cin >> N;
  int l = 0;     // 文字列の長さ
  int64_t M = N; // コピーした！
  string s;      // こたえ

  for (int i = 1; i < 100; i++) { // 100もあれば十分
    M -= pow(26LL, i);
    l++;
    if (M <= 0) {
      M += pow(26LL, i);
      M--;
      break;
    }
  }

  for (int i = 0; i < l; i++) {
    int64_t r;
    r = M % 26;
    char v = nth_letter(r);
    s += v;
    M /= 26;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
}

Error: 0

Fixed submission:

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

char nth_letter(int n) {
  assert(n >= 1 && n <= 26);
  return "abcdefghijklmnopqrstuvwxyz"[n - 1];
}

int main() {
  int64_t N;
  cin >> N;
  int l = 0;     // 文字列の長さ
  int64_t M = N; // コピーした！
  string s;      // こたえ

  for (int i = 1; i < 100; i++) { // 100もあれば十分
    M -= pow(26LL, i);
    l++;
    if (M <= 0) {
      break;
    }
  }

  for (int i = 0; i < l; i++) {
    int r;
    r = N % 26;
    char v = nth_letter(r);
    s += v;
    N /= 26;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

signed main() {
  int N;
  cin >> N;
  string alfa = "abcdefghijklmnopqrstuvwxyz";
  string ans = "";
  while (N > 0) {
    int A = N % 26;
    A--;
    if (A < 0)
      A = 25;
    ans += alfa.at(A);
    if (A == 25)
      N--;
    N /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

signed main() {
  int N;
  cin >> N;
  string alfa = "abcdefghijklmnopqrstuvwxyz";
  string ans = "";
  while (N > 0) {
    ans += alfa.at(N % 26 - 1);
    N /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

vector<char> word;

void remainder(long long int n) {
  if (n != 0) {
    if (n / 26 < 1) {
      word.push_back('a' + n % 26 - 1);
    } else if (n / 26 >= 1) {
      if ((n % 26) == 0) {
        word.push_back('z');
        if (n > 26)
          remainder((n - 26) / 26);
        else
          return;
      } else {
        word.push_back('a' + n % 26 - 1);
        remainder(n / 26);
      }
    }
  } else {
    return;
  }
}

int main() {
  long long int num;
  cin >> num;
  remainder(num);
  for (int i = word.size() - 1; i >= 0; i--)
    cout << word[i];
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

vector<char> word;

void remainder(long long int n) {
  if (n != 0) {
    if (n / 26 < 1) {
      word.push_back('a' + n % 26 - 1);
    } else if (n / 26 >= 1) {
      if ((n % 26) == 0) {
        word.push_back('z');
        if (n > 26)
          remainder((n - 26) / 26);
        else
          return;
      } else {
        word.push_back('a' + n % 26 - 1);
        remainder(n / 26);
      }
    }
  } else {
    return;
  }
}

int main() {
  for (int k = 0;; k++) {
    long long int num;
    cin >> num;
    remainder(num);
    for (int i = word.size() - 1; i >= 0; i--)
      cout << word[i];
    cout << endl;
    word.clear();
  }

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

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
#define rep(i, N) for (int i = 0; i < N; i++)
using namespace std;
int main() {
  long int N;
  // int K=10000000;
  // rep(k,K){
  // N=k+1;
  cin >> N;
  long int order = (long int)ceil(log(N) / log(26));
  if (N == 1)
    order = 1;
  // cout <<order;
  vector<long int> ans(order);
  long int temp = N;
  string list[26] = {"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"};
  for (int i = order - 1; i >= 0; i--) {
    ans.at(i) = (long int)temp / pow(26, i);
    //    cout <<fixed<<temp<<" "<<ans.at(i)<<"    "<<pow(26,i)<<endl;
    temp = temp - (long int)pow(26, i) * ans.at(i);
  }
  rep(i, order - 1) {
    if (ans.at(i) <= 0) {
      ans.at(i) += 26;
      ans.at(i + 1)--;
    }
  }
  if (ans.at(order - 1) == 0) {
    order--;
  }

  string a = "";
  for (int i = order - 1; i >= 0; i--) {
    //  cout<<a<<endl;
    a = a + list[ans.at(i) - 1];
  }
  cout << a << endl;
  //}
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
#define rep(i, N) for (int i = 0; i < N; i++)
using namespace std;
int main() {
  int N;
  // int K=10000;
  //    rep(k,K){
  //  N=k+1;
  cin >> N;
  long int order = (long int)ceil(log(N) / log(26));
  vector<long int> ans(order);
  long int temp = N;
  string list[26] = {"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"};
  for (int i = order - 1; i >= 0; i--) {
    ans.at(i) = (long int)temp / pow(26, i);
    //      cout <<fixed<<temp<<" "<<ans.at(i)<<"    "<<pow(26,i)<<endl;
    temp = temp - (long int)pow(26, i) * ans.at(i);
  }
  rep(i, order - 1) {
    if (ans.at(i) <= 0) {
      ans.at(i) += 26;
      ans.at(i + 1)--;
    }
  }
  if (ans.at(order - 1) == 0) {
    order--;
  }

  string a = "";
  for (int i = order - 1; i >= 0; i--) {
    //     cout<<a<<endl;
    a = a + list[ans.at(i) - 1];
  }
  cout << a << endl;
  //   }
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

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

template <typename T> T ipow(T b, long long e) {
  if (e == 0) {
    return 1;
  } else if (e % 2 == 0) {
    return ipow(b * b, e / 2);
  } else {
    return ipow(b * b, e / 2) * b;
  }
}

// aを1番目、zを26番目としてx番目のcharを返す
char get_char(int x) { return 'a' - 1 + x; }

int main() {
  long long N;
  cin >> N;
  int i = 1;
  while (N > ipow<long long>(26, i)) {
    N -= ipow<long long>(26, i);
    i++;
  }
  string ans;
  // i文字の名前のうち、N番目を計算して出力
  for (int j = i; j > 0; j--) {
    int c = 1;
    while (N > ipow<long long>(26, j - 1)) {
      N -= ipow<long long>(26, j - 1);
      c++;
    }
    ans += get_char(c);
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

template <typename T> T ipow(T b, long long e) {
  if (e == 0) {
    return 1;
  } else if (e % 2 == 0) {
    return ipow(b * b, e / 2);
  } else {
    return ipow(b * b, e / 2) * b;
  }
}

// aを1番目、zを26番目としてx番目のcharを返す
char get_char(int x) { return 'a' - 1 + x; }

int main() {
  long long N;
  cin >> N;
  int i = 1;
  while (N > ipow<long long>(26, i)) {
    N -= ipow<long long>(26, i);
    i++;
  }
  string ans;
  // i文字の名前のうち、N番目を計算して出力
  for (int j = i; j > 0; j--) {
    int c = 1;
    while (N > ipow(26, j - 1)) {
      N -= ipow(26, j - 1);
      c++;
    }
    ans += get_char(c);
  }
  cout << ans << endl;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int64_t N;
  cin >> N;
  int a_int = int('a');
  string ans = "";
  /*
  while(N != 0){
      int d = N % 26;
      N = N / 26;
      char c = (char)(a_int+d);
      ans += c;
  }
  char a = ans.at(0)
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  */

  int keta = 1;
  int64_t old_keta_max = 0;
  int64_t keta_max = 26;
  int64_t M = 26;
  while (keta_max < N) {
    keta++;
    old_keta_max = keta_max;
    M = M * 26;
    keta_max += M;
  }
  int64_t f = N - old_keta_max;
  f--;
  for (int i = 0; i < keta; i++) {
    int d = f % 26;
    f = f / 26;
    char c = (char)(a_int + d);
    ans += c;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int64_t N;
  cin >> N;
  int a_int = int('a');
  string ans = "";
  /*
  while(N != 0){
      int d = N % 26;
      N = N / 26;
      char c = (char)(a_int+d);
      ans += c;
  }
  char a = ans.at(0)
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  */

  int keta = 1;
  int old_keta_max = 0;
  int keta_max = 26;
  while (keta_max < N) {
    keta++;
    old_keta_max = keta_max;
    keta_max += pow(26, keta);
  }
  int f = N - old_keta_max;
  f--;
  for (int i = 0; i < keta; i++) {
    int d = f % 26;
    f = f / 26;
    char c = (char)(a_int + d);
    ans += c;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {

  long long n;
  long long tmp;
  long long count = 0;
  long long que = -1;
  char *str;

  cin >> n;
  que = n;
  tmp = que;
  count = 1;
  while (que) {
    que /= 26;
    count++;
  }

  str = (char *)malloc(count);
  que = n;
  // tmp = que;
  count = 0;
  while (que > 0) {
    que--;
    // tmp %= 26;

    // cout << tmp << " " << que <<endl;
    str[count++] = 'a' + (que % 26);
    que /= 26;
    // tmp = que;
  }

  for (long long i = count - 1; i >= 0; i--)
    cout << str[i];

  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  int n;
  int tmp;
  int count = 0;
  int que = -1;
  char str[1000000000000002];

  cin >> n;
  que = n;
  tmp = que;
  while (que) {

    tmp %= 26;
    que /= 26;
    str[count++] = 'a' - 1 + tmp;
    tmp = que;
  }

  for (int i = count - 1; i >= 0; i--)
    cout << str[i];

  return 0;
}
Problem p02629 (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 repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                                                             \\
  ifstream in("abc171/abc171_c.txt");                                          \\
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                                                           \\
  rep(l, v.size()) { cout << v[l] << " "; }                                    \\
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE                                                           \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  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: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                                                             \\
  ifstream in("abc171/abc171_c.txt");                                          \\
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                                                           \\
  rep(l, v.size()) { cout << v[l] << " "; }                                    \\
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE                                                           \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  ll N;
  cin >> N;
  ll M = 1000000000000001;
  vector<int> c(N);
  string ans = "";
  for (int i = 10; i >= 0; i--) {
    ll p = pow(26, i);
    ll bit = N / p;
    if (bit > 0) {
      ans += 'a' + bit - 1;
    }
    N %= p;
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
i64 N, Len;
string ans;
inline void pre() {
  i64 l = 1, Bas = 26, Ans = 26;
  while (Ans < N) {
    Ans += (Bas *= 26);
    l++;
  }
  ans = string(l, 'a');
  N -= Ans - Bas;
  Len = l;
}
inline void work() {
  pre();
  N--;
  i64 Bas = 1, Cur = 0;
  for (int i = 1; i < Len; i++)
    Bas *= 26;
  while (Cur < ans.size()) {
    while (N >= Bas)
      N -= Bas, ans[Cur]++;
    Cur++;
    Bas /= 26;
  }
  cout << ans;
}
int main() {
  cin >> N;
  work();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
i64 N, Len;
string ans;
inline void pre() {
  i64 l = 1, Bas = 26, Ans = 26;
  while (Ans < N) {
    Ans += (Bas *= 26);
    l++;
  }
  ans = string(l, 'a');
  N -= Ans - Bas;
  Len = l;
}
inline void work() {
  pre();
  N--;
  int Bas = 1, Cur = 0;
  for (int i = 1; i < Len; i++)
    Bas *= 26;
  while (Cur < ans.size()) {
    while (N >= Bas)
      N -= Bas, ans[Cur]++;
    Cur++;
    Bas /= 26;
  }
  cout << ans;
}
int main() {
  cin >> N;
  work();
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long keta = 1;
vector<int> cnt(1, 0);

string res(long long N) {
  string ans = "";
  string alp = "abcdefghijklmnopqrstuvwxyz";
  while (N > 0) {
    N -= 1;
    ans = alp.at(N % 26) + ans;
    N = N / 26;
  }
  return ans;
}

int main() {
  long long N;
  cin >> N;
  cout << res(N);
}

Error: TLE

Fixed submission:

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

long long keta = 1;
vector<int> cnt(1, 0);

void saiki(long long keta, long long i) { // i: 今の桁
  if (cnt.at(i) < 26) {
    cnt.at(i)++;
    if (cnt.at(i) == 26) {
      cnt.at(i) = 0;
      saiki(keta, i + 1);
    } else
      return;
  } else
    saiki(keta, i + 1);
}

void ans(long long keta, long long N, long long lower, long long upper) {
  vector<char> alp{'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'};
  string res = "";
  long long now = lower;
  while (now != N) {
    saiki(keta, 0);
    now++;
  }
  for (long long i = keta - 1; i >= 0; i--)
    cout << alp.at(cnt.at(i));
}

int main() {
  long long N;
  cin >> N;
  long long lower = 1;
  long long upper = 26;
  while (true) {
    if (N <= upper) {
      ans(keta, N, lower, upper);
      return 0;
    }
    keta++;
    cnt.push_back(0);
    lower = upper + 1;
    upper = upper + pow(26, keta);
  }
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int, int>
#define mod 1000000007
#define endl "\\n"

int power(int a, int b, int m = mod) {
  if (b == 0)
    return 1;
  if (b == 1)
    return a;
  int res = power(a, b / 2, m);
  res = (res * res) % m;
  if (b & 1)
    res = (res * a) % m;
  return res;
}
int modinv(int a, int m = mod) { return power(a, m - 2, m); }
int add(int a, int b, int m = mod) {
  int c = (a % m + b % m);
  if (c >= m)
    c -= m;
  return c;
}
int sub(int a, int b, int m = mod) {
  int c = (a % m - b % m);
  if (c < 0)
    c += m;
  return c;
}
int mul(int a, int b, int m = mod) { return (a * b) % m; }
//	x<<1 => x*2		x>>1 => x/2;	cout<<flush;
//	cout<<fixed<<setprecision(10)<<ans<<endl;

void solve() {
  int n;
  cin >> n;
  string s;
  while (n) {
    int x = (n - 1) % 26;
    char c = x + 'a';
    s += c;
    n = (n - 1) / 26;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1; // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int, int>
#define mod 1000000007
#define endl "\\n"

int power(int a, int b, int m = mod) {
  if (b == 0)
    return 1;
  if (b == 1)
    return a;
  int res = power(a, b / 2, m);
  res = (res * res) % m;
  if (b & 1)
    res = (res * a) % m;
  return res;
}
int modinv(int a, int m = mod) { return power(a, m - 2, m); }
int add(int a, int b, int m = mod) {
  int c = (a % m + b % m);
  if (c >= m)
    c -= m;
  return c;
}
int sub(int a, int b, int m = mod) {
  int c = (a % m - b % m);
  if (c < 0)
    c += m;
  return c;
}
int mul(int a, int b, int m = mod) { return (a * b) % m; }
//	x<<1 => x*2		x>>1 => x/2;	cout<<flush;
//	cout<<fixed<<setprecision(10)<<ans<<endl;

void solve() {
  int n, k;
  cin >> n >> k;
  int a[n], i, ans = 0;
  for (i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (i = 0; i < k; i++)
    ans += a[i];
  cout << ans << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1; // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

#define ll unsigned long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
string convertToTitle(ll n) {
  string r = "";
  while (n > 0) {
    r = (char)(97 + (n - 1) % 26) + r;
    n = (n - 1) / 26;
  }
  return r;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    ll n;
    cin >> n;
    cout << convertToTitle(n);
  }
  return 0;
}


Error: WA

Fixed submission:

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

#define ll unsigned long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    ll n;
    cin >> n;
    ll arr[20];
    arr[0] = 1;
    arr[1] = 26;
    for (int i = 2; i <= 13; i++) {
      arr[i] = arr[i - 1] * 26;
    }
    string s;
    s = "";
    for (int i = 13; i >= 0; i--) {
      if (arr[i] <= n || s.size() > 0) {
        ll temp = n / arr[i];
        char p = 'a' + temp - 1;
        s += p;
        temp = temp * arr[i];
        n = n % temp;
      }
    }
    cout << s;
  }
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long n;
  string s = "abcdefghijklmnopqrstuvwxyz";
  vector<long long> x(11);
  cin >> n;
  string ans;

  x.at(0) = 1;
  for (int i = 1; i < 11; i++) {
    x.at(i) = x.at(i - 1) + pow(26, i);
  }
  for (long long i = 10; i >= 0; i--) {
    if (n >= x.at(i)) {
      ans = ans + s.at(int((n - x.at(i)) / pow(26, i)));
      n = n - (int((n - x.at(i)) / pow(26, i)) + 1) * pow(26, i);
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int main() {
  long long n;
  string s = "abcdefghijklmnopqistuvwxyz";
  vector<long long> x(11);
  cin >> n;
  string ans;

  x.at(0) = 1;
  for (int i = 1; i < 11; i++) {
    x.at(i) = x.at(i - 1) + pow(26, i);
  }
  for (long long i = 10; i >= 0; i--) {
    if (n >= x.at(i)) {
      if (i == 0) {
        ans = ans + s.at(int((n - (x.at(i) - 1)) / pow(26, i)) - 1);
      } else {
        ans = ans + s.at(int((n - (x.at(i) - 1)) / pow(26, i)));
      }
      n = n - (int((n - (x.at(i) - 1)) / pow(26, i)) + 1) * pow(26, i);
    }
  }
  cout << ans << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

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

Error: -11

Fixed submission:

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

int main() {
  int n, cnt = 0;
  cin >> n;
  while (n / pow(26, cnt) > 26)
    cnt++;
  char *ans;
  for (int i = 0; i < cnt + 1; i++) {
    ans[i] = n / pow(26, cnt - i) - 1 + 'a';
    while (n > pow(26, cnt - i))
      n -= pow(26, cnt - i);
  }
  cout << ans << endl;
}