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

#include <cstdio>

int main() {
  long long num;

  scanf("%lld", &num);

  int digit = 1;
  long long start = 1;
  long long niroku = 26;

  for (;;) {
    if (start <= num && num < start + niroku)
      break;
    else {
      digit++;
      start += niroku;
      niroku *= 26;
    }
  }

  num -= start;
  niroku /= 26;

  // fprintf(stderr, "dig: %d num: %lld", digit, num);

  int i;
  for (i = 0; i < digit; i++) {
    putchar('a' + num / niroku);
    num %= niroku;
    niroku /= 26;
  }

  printf("\\n");

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
  // printf("%lu", sizeof(long long));
  long long num;
  char s[10];

  int i;
  for (i = 0; i < 10; i++) {
    s[i] = '\\0';
  }

  scanf("%lld", &num);

  int p = 0;
  while (num != 0) {
    s[p++] = 'a' - 1 + num % 26;
    num /= 26;
  }

  reverse(s, s + p);

  printf("%s\\n", s);

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

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <set>
#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>;

using namespace std;

int main() {
  ll N;
  cin >> N;
  string ret = "";

  while (N) {
    --N;
    ret += (char)('a' + (N % 26));
    N /= 26;
  }

  reverse(ret.begin(), ret.end());
  cout << ret << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <set>
#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>;

using namespace std;

int main() {
  ll N, md, t;
  string ret = "";
  vector<int> st;
  cin >> N;

  N = N - 1;
  while (N != 0) {
    md = N % 26;
    st.push_back(md);
    t = (N - md) / 26;

    if ((N - md) == 0) {
      break;
    }

    if (t == 1) {
      st.push_back(1);
      break;
    }
    N = t;
  }

  // N - 1を戻す
  st.at(0) += 1;
  std::reverse(st.begin(), st.end());

  for (int j = 0; j < st.size(); ++j) {
    if (st.at(j) == 1)
      ret += 'a';
    if (st.at(j) == 2)
      ret += 'b';
    if (st.at(j) == 3)
      ret += 'c';
    if (st.at(j) == 4)
      ret += 'd';
    if (st.at(j) == 5)
      ret += 'e';
    if (st.at(j) == 6)
      ret += 'f';
    if (st.at(j) == 7)
      ret += 'g';
    if (st.at(j) == 8)
      ret += 'h';
    if (st.at(j) == 9)
      ret += 'i';
    if (st.at(j) == 10)
      ret += 'j';
    if (st.at(j) == 11)
      ret += 'k';
    if (st.at(j) == 12)
      ret += 'l';
    if (st.at(j) == 13)
      ret += 'm';
    if (st.at(j) == 14)
      ret += 'n';
    if (st.at(j) == 15)
      ret += 'o';
    if (st.at(j) == 16)
      ret += 'p';
    if (st.at(j) == 17)
      ret += 'q';
    if (st.at(j) == 18)
      ret += 'r';
    if (st.at(j) == 19)
      ret += 's';
    if (st.at(j) == 20)
      ret += 't';
    if (st.at(j) == 21)
      ret += 'u';
    if (st.at(j) == 22)
      ret += 'v';
    if (st.at(j) == 23)
      ret += 'w';
    if (st.at(j) == 24)
      ret += 'x';
    if (st.at(j) == 25)
      ret += 'y';
    if (st.at(j) == 26)
      ret += 'z';
  }

  cout << ret << endl;

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

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;
const ll K_MAX = 1e5 + 5;
const int INF = 1e9;

ll pow2(ll a, int b) {
  if (b == 1) {
    return a;
  } else {
    return pow2(a, b - 1) * a;
  }
};

int main() {
  ll n;
  cin >> n;
  vector<ll> a(12);
  ll temp = 1;
  a[0] = 1;
  rep1(i, 11) {
    temp *= 26;
    a[i] = temp;
  }

  vector<string> abc(26);
  vector<ll> c(12); // 桁数iのものの最大数
  c[0] = 0;
  temp = 1;

  for (int i = 1; i <= 11; i++) {
    temp *= ll(26);
    c[i] = c[i - 1] + temp;
  }

  abc = {"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"};

  int keta = 0;

  for (int j = 11; j > 0; j--) {
    if (n > c[j]) { // 桁数
      keta = j + 1;
      break;
    }
  }
  vector<ll> st(keta);
  // cout<<"keta"<<keta;
  if (keta == 0) {
    cout << abc[n - 1];
    return 0;
  }

  ll now = n - c[keta - 1] - 1; // 000=aaa
  for (int i = keta - 1; i >= 0; i--) {
    st[i] = now / a[i];
    cout << abc[st[i]];
    now -= a[i] * st[i];
  }
}


Error: WA

Fixed submission:

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;
const ll K_MAX = 1e5 + 5;
const int INF = 1e9;

ll pow2(ll a, int b) {
  if (b == 1) {
    return a;
  } else {
    return pow2(a, b - 1) * a;
  }
};

int main() {
  ll n;
  cin >> n;
  vector<ll> a(12);
  ll temp = 1;
  a[0] = 1;
  rep1(i, 11) {
    temp *= 26;
    a[i] = temp;
  }

  vector<string> abc(26);
  vector<ll> c(12); // 桁数iのものの最大数
  c[0] = 0;
  temp = 1;

  for (int i = 1; i <= 11; i++) {
    temp *= ll(26);
    c[i] = c[i - 1] + temp;
  }

  abc = {"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"};

  int keta = 0;

  for (int j = 11; j > 0; j--) {
    if (n > c[j]) { // 桁数
      keta = j + 1;
      break;
    }
  }
  vector<int> st(keta);

  if (keta == 0) {
    cout << abc[n - 1];
    return 0;
  }

  ll now = n;
  for (int i = keta - 1; i >= 0; i--) {
    st[i] = now / a[i];
    if (st[i] >= 27) {
      st[i] = 26;
    }
    now -= st[i] * a[i];
    cout << abc[st[i] - 1];
  }
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (lol i = 0; i < lol(n); i++)
#define REPD(i, n) for (lol i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (lol i = a; i <= lol(b); i++)
#define FORD(i, a, b) for (lol i = a; i >= lol(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) lol(x.size())     // sizeをsize_tからllに直しておく
// 定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007    // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 最大値最小値
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

char NumToCh(lol num);
vector<char> c;
int nums;

int main() {
  lol n;
  cin >> n;
  lol a[12], k;
  lol index;

  a[0] = 0;
  FOR(i, 1, 12) {
    a[i] = pow(26, i) + a[i - 1];
    if (n <= a[i]) {
      k = n - a[i - 1] - 1;
      index = i;
      break;
    }
  }
  REP(i, index) {
    c.push_back(NumToCh(k % 26));
    k = k / 26;
  }
  REPD(i, index)
  cout << c[i];
  cout << endl;
  return 0;
}

char NumToCh(lol num) {

  int i = (int)'a';
  return (char)(i + num);
}

Error: 0

Fixed submission:

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

// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (lol i = 0; i < lol(n); i++)
#define REPD(i, n) for (lol i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (lol i = a; i <= lol(b); i++)
#define FORD(i, a, b) for (lol i = a; i >= lol(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) lol(x.size())     // sizeをsize_tからllに直しておく
// 定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007    // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 最大値最小値
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

char NumToCh(lol num);
vector<char> c;
int nums;

int main() {
  lol n;
  cin >> n;
  lol a[11], k;
  lol index;

  // int k; cin >> k;
  /*
  vector<int> a(n);
  REP(i, n)
  {
      cin >> a[i];
  }
  */
  a[0] = 0;
  // a[1] = 26;
  FOR(i, 1, 12) {
    a[i] = pow(26, i) + a[i - 1];
    if (n <= a[i]) {
      k = n - a[i - 1] - 1;
      index = i;
      break;
    }
  }
  REP(i, index) {
    c.push_back(NumToCh(k % 26));
    k = k / 26;
  }
  REPD(i, index)
  cout << c[i];
  cout << endl;
  return 0;
}

char NumToCh(lol num) {

  int i = (int)'a';
  return (char)(i + num);
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

/*    created: 09.08.2020 22:41:29    */

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; // 最大値

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main() {
  ll n;
  cin >> n;
  string s = "abcdefghijklmnopqrstuvwxyz", ans = "";

  while (true) {
    n--;
    if (n < 26) {
      ans.PB(s[n]);
      reverse(ALL(ans));
      cout << ans << endl;
      return 0;
    }
    ll tmp = n % 26;
    n /= 26;
    ans.PB(s[tmp]);
  }
}

Error: WA

Fixed submission:

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; // 最大値

ll dp[MX][MX];
inline void chmax(ll &a, ll b) { a = max(a, b); }

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back

int main() {
  ll n, q;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a.at(i);
  cin >> q;
  vector<ll> b(q), c(q);
  rep(i, q) cin >> b.at(i) >> c.at(i);
  ll cnt = 0;
  rep(i, n) cnt += a.at(i);

  vector<ll> set(100005, 0);
  rep(i, n) { set.at(a.at(i))++; }

  rep(i, q) {
    ll tmp = set.at(b.at(i));
    set.at(c.at(i)) += tmp;
    cnt += (c.at(i) - b.at(i)) * tmp;
    cout << cnt << endl;
  }
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

char f(int i) {
  if (i == 1)
    return 'a';
  if (i == 2)
    return 'b';
  if (i == 3)
    return 'c';
  if (i == 4)
    return 'd';
  if (i == 5)
    return 'e';
  if (i == 6)
    return 'f';
  if (i == 7)
    return 'g';
  if (i == 8)
    return 'h';
  if (i == 9)
    return 'i';
  if (i == 10)
    return 'j';
  if (i == 11)
    return 'k';
  if (i == 12)
    return 'l';
  if (i == 13)
    return 'm';
  if (i == 14)
    return 'n';
  if (i == 15)
    return 'o';
  if (i == 16)
    return 'p';
  if (i == 17)
    return 'q';
  if (i == 18)
    return 'r';
  if (i == 19)
    return 's';
  if (i == 20)
    return 't';
  if (i == 21)
    return 'u';
  if (i == 22)
    return 'v';
  if (i == 23)
    return 'w';
  if (i == 24)
    return 'x';
  if (i == 25)
    return 'y';
  if (i == 0)
    return 'z';
}

int main() {
  long long n;
  cin >> n;
  string ans = "";

  while (n >= 1) {
    ans = f((n % 26)) + ans;
    if (n % 26 == 0) {
      n -= 1;
      n /= 26;
    } else {
      n /= 26;
    }
  }

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

Error: -11

Fixed submission:

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

char f(int i) {
  if (i == 1)
    return 'a';
  if (i == 2)
    return 'b';
  if (i == 3)
    return 'c';
  if (i == 4)
    return 'd';
  if (i == 5)
    return 'e';
  if (i == 6)
    return 'f';
  if (i == 7)
    return 'g';
  if (i == 8)
    return 'h';
  if (i == 9)
    return 'i';
  if (i == 10)
    return 'j';
  if (i == 11)
    return 'k';
  if (i == 12)
    return 'l';
  if (i == 13)
    return 'm';
  if (i == 14)
    return 'n';
  if (i == 15)
    return 'o';
  if (i == 16)
    return 'p';
  if (i == 17)
    return 'q';
  if (i == 18)
    return 'r';
  if (i == 19)
    return 's';
  if (i == 20)
    return 't';
  if (i == 21)
    return 'u';
  if (i == 22)
    return 'v';
  if (i == 23)
    return 'w';
  if (i == 24)
    return 'x';
  if (i == 25)
    return 'y';
  if (i == 0)
    return 'z';
}

int main() {
  ll n;
  cin >> n;
  string ans[100000000];
  ll k = 0;

  while (n >= 1) {
    ans[k] = f((n % 26));
    k += 1;
    n /= 26;
  }

  for (ll i = k; i >= 0; --i) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define rep(i, f, t) for (int i = f; i < t; i++)
using namespace std;
int solve() {
  ll n;
  cin >> n;
  string s;
  while (n--) {
    char c = n % 26 + 'a';
    s = c + s;
    n /= 26;
  }
  cout << s << endl;
  return 0;
}
int main() {
  int t = 1;
  //	cin>>t;
  while (t--) {
    solve();
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#define ll long long
#define rep(i, f, t) for (int i = f; i < t; i++)
using namespace std;
int solve() {
  ll n;
  cin >> n;
  string s;
  while (n--) {
    char c = n % 26 + 'a';
    s = c + s;
    n /= 26;
  }
  cout << s << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())
const double pi = 3.14159265358979323846;

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

  ll i, j, n;
  cin >> n;
  vector<ll> a(12);
  a[0] = 0;
  for (i = 1; i < 12; i++)
    a[i] = a[i - 1] + pow(26, i);
  // for(auto k: a) cout<<k<<" ";
  i = 1;
  while (a[i] < n)
    i++;
  ll diff = n - a[i - 1] - 1;
  vector<ll> r;
  while (diff) {
    r.pb(diff % 26);
    diff /= 26;
  }
  if (r.empty()) {
    for (j = 0; j < i; j++)
      cout << 'a';
    return 0;
  }
  reverse(all(r));
  vector<char> ch;
  for (auto e : r) {
    ch.pb(char('a' + e));
  }
  ll rem = i - sz(ch);
  for (j = 0; j < rem; j++)
    cout << 'a';
  for (auto s : ch)
    cout << s;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())
const double pi = 3.14159265358979323846;

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

  ll i, j, n;
  cin >> n;
  vector<ll> a(11);
  a[0] = 0;
  for (i = 1; i < 11; i++)
    a[i] = a[i - 1] + pow(26, i);
  // for(auto k: a) cout<<k<<" ";
  i = 1;
  while (a[i] < n)
    i++;
  ll diff = n - a[i - 1] - 1;
  vector<ll> r;
  while (diff) {
    r.pb(diff % 26);
    diff /= 26;
  }
  if (r.empty()) {
    for (j = 0; j < i; j++)
      cout << 'a';
    return 0;
  }
  reverse(all(r));
  for (auto e : r) {
    cout << char('a' + e);
  }
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Bsort(a) sort(a.begin(), a.end(), greater<ll>())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll n;
  cin >> n;
  vector<ll> a;
  for (ll i = 0;; i++) {
    ll t = n % 26;
    if (t == 0)
      a.push_back(26);
    else
      a.push_back(t);
    n /= 26;
    if (t == 0)
      n--;
    if (n == 0) {
      break;
    }
  }
  for (ll i = a.size() - 1; i >= 0; i--) {
    cout << char(a[i] + 96);
  }
  cout << '\\n';
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Bsort(a) sort(a.begin(), a.end(), greater<ll>())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll n;
  cin >> n;
  vector<ll> a;
  if (n % 26 == 0) {
    return 1;
  }
  for (ll i = 0;; i++) {
    ll t = n % 26;
    if (t == 0)
      a.push_back(26);
    else
      a.push_back(t);
    n /= 26;
    if (t == 0)
      n--;
    if (n == 0 || (n == 1 && t == 0)) {
      break;
    }
  }
  rep(i, a.size()) { cout << char(a[a.size() - 1 - i] + 96); }
  cout << '\\n';
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

ll powm(ll b, ll p) {
  if (p == 0)
    return 1;
  if (p % 2 == 1)
    return b * powm(b, p - 1);
  else {
    ll t = powm(b, p / 2);
    return t * t;
  }
}

int main() {
  ll n;
  cin >> n;
  ll md, count = 0;
  for (md = 0; 1; md++) {
    count += powm(26, md);
    if (count > n)
      break;
  }
  vector<int> s(md);
  for (int i = 1; i <= md; i++) {
    s[i - 1] = n % 26;
    if (s[i - 1] == 0) {
      s[i - 1] = 26;
      n -= 26;
    }
    n /= 26;
  }
  for (int i = md - 1; i >= 0; i--) {
    char t = 'a' + s[i] - 1;
    cout << t;
  }
  cout << endl;
}


Error: 0

Fixed submission:

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

ll pow(ll b, ll p) {
  if (p == 0)
    return 1;
  if (p % 2 == 1)
    return b * pow(b, p - 1);
  else {
    ll t = pow(b, p / 2);
    return t * t;
  }
}

int main() {
  ll n;
  cin >> n;
  int max, maxt = 0;
  for (int i = 1; i < 20; i++) {
    maxt += pow(26, i);
    if (maxt > n) {
      max = i;
      break;
    }
  }
  vector<int> s(20, 0);
  for (int i = max - 1; i >= 0; i--) {
    s[max - 1 - i] = n / pow(26, i);
    n -= pow(26, i) * s[max - 1 - i];
  }
  for (int i = 0; i <= max - 1; i++) {
    char t = char(97 + s[i] - 1);
    cout << t;
  }
  cout << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

// 26進数に変換する関数
vector<int> change(long n) {
  vector<int> a;
  while (1) {
    if (n < 26) {
      a.push_back(n);
      break;
    } else {
      a.push_back(n % 26);
      n = n / 26;
    }
  }
  return a;
}

int main() {
  long n;
  cin >> n;
  vector<int> a = change(n); // nを26進数に変換 #26進数を逆順で表記
  string alp, name;
  alp = "abcdefghijklmnopqrstuvwxy";

  for (long i = 0; i < a.size() - 1; i++) {
    if (a.at(i) != 0)
      name.push_back(alp.at(a.at(i) - 1));
    else {
      name.push_back('z');
      for (long j = 1; i + j < a.size(); j++) {
        if (a.at(i + j) != 0) {
          a.at(i + j) -= 1;
          break;
        } else
          a.at(i + j) = 25;
      }
    }
  }
  if (a.at(a.size() - 1) != 0)
    name.push_back(alp.at(a.at(a.size() - 1) - 1));

  reverse(name.begin(), name.end());
  cout << name << endl;
}

Error: 0

Fixed submission:

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

// 26進数に変換する関数
vector<int> change(long n) {
  vector<int> a;
  while (1) {
    if (n < 26) {
      a.push_back(n);
      break;
    } else {
      a.push_back(n % 26);
      n = n / 26;
    }
  }
  return a;
}

int main() {
  long n;
  cin >> n;
  vector<int> a = change(n); // nを26進数に変換 #26進数を逆順で表記
  string alp, name;
  alp = "abcdefghijklmnopqrstuvwxy";

  for (long i = 0; i < a.size(); i++) {
    if (a.at(i) != 0)
      name.push_back(alp.at(a.at(i) - 1));
    else {
      name.push_back('z');
      for (long j = 1; j < a.size(); i++) {
        if (a.at(i + j) != 0) {
          a.at(i + j) -= 1;
          break;
        } else
          a.at(i + j) = 25;
      }
    }
  }
  reverse(name.begin(), name.end());
  cout << name << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

int main() {
  string s;
  long long N;
  long long d = 1;
  int result[15] = {0};
  int i = 0;
  int l;
  cin >> N;
  while (N >= 0) {
    N -= d;
    d *= 26;
    result[i]++;
    i++;
  }
  i--;
  l = i;
  d /= 26;
  N += d;
  while (d >= 1) {
    result[i] += N / d;
    N %= d;
    d /= 26;
    i--;
  }
  for (int m = l - 1; m >= 0; m--) {
    s += (result[m] + 'a' - 1);
  }
  cout << s;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

int main() {
  string s;
  long long N;
  long long d = 1;
  int result[7] = {0};
  int i = 0;
  int l;
  cin >> N;
  while (N >= 0) {
    N -= d;
    d *= 26;
    result[i]++;
    i++;
  }
  i--;
  l = i;
  d /= 26;
  N += d;
  while (d >= 1) {
    result[i] += N / d;
    N %= d;
    d /= 26;
    i--;
  }
  for (int m = l - 1; m >= 0; m--) {
    s += (result[m] + 'a' - 1);
  }
  cout << s;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  char x[10010];
  long long a, t = 26, c = 0, start, cha, i = 0; // c代表长度
  scanf("%lld", &a);
  while (a > i) {
    i += t;
    t *= 26;
    c++;
  }
  start = i - (t / 26) + 1;
  for (int n = 0; n < c; n++)
    x[n] = 97;
  cha = a - start;
  // cout<<"i c start cha"<<endl<<i<<" "<<c<<" "<<start<<" "<<cha<<endl;
  int n = 0;
  while (cha > 0) {
    //	cout<<cha<<' '<<cha%26<<endl;
    x[n] += (cha % 26);
    cha /= 26;
    n++;
  }
  for (int n = c - 1; n >= 0; n--)
    cout << x[n];
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  char x[10010];
  long long a, i = 26, c = 1, start; // c代表长度
  cin >> a;
  while (a > i) {
    i *= 27;
    c++;
  }
  start = i / 27 + 1;
  for (int n = 0; n < c; n++)
    x[n] = 97;
  for (int m = start + 1, n = 0; m <= a; m++) {
    if (x[n] == 122) {
      x[n] = 97;
      n++;
      continue;
    }
    x[n]++;
  }
  for (int n = c - 1; n >= 0; n--)
    cout << x[n];
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  long long d_count = 0;
  // string s = "abcdefghijklmnopqrstuvwxyz";
  string ans_rev;
  string ans;

  while (N > 0) {
    d_count++;
    N--;
    long long j = N % 26;
    ans_rev += ((char)'a' + (j));
    N = N / 26;
  }

  for (long long i = d_count - 1; i >= 0; i--) {
    cout << ans_rev[i];
  }
  cout << endl;
}


Error: TLE

Fixed submission:

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

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

  unsigned long long count = 1;
  unsigned long long d_count = 0;

  while (count <= N) {
    d_count++;
    count = count * 26;
  }

  char C[d_count];
  string s = "abcdefghijklmnopqrstuvwxyz";
  string ans;

  for (unsigned long long i = d_count; i >= 0; i--) {
    unsigned long long j = N % 26;
    N = N / 26;
    C[i] = s[j - 1];
  }

  for (unsigned long long i = 0; i <= d_count; i++) {
    ans += C[i];
  }
  cout << ans << endl;
}