Problem p02848 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define se second
#define mp make_pair
#define fi first
#define del(a, vec)                                                            \
  vec.erase(std::remove(vec.begin(), vec.end(), a), vec.end());
#define search(f, l, v) binary_search(f, l, v)
#define iter(a, b) vector<int>::iterator a, b
#define lower(v, num) lower_bound(v.begin(), v.end(), num);
#define upper(v, num) upper_bound(v.begin(), v.end(), num);
#define removecopy(a) unique(a.begin(), a.end());
#define ll long long int
namespace Rahul {
bool isPrime(int n) {
  if (n <= 1)
    return false;
  if (n <= 3)
    return true;
  if (n % 2 == 0 || n % 3 == 0)
    return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0)
      return false;
  return true;
}
ll pow(ll x, ll n, ll mod) { // calculate x^n
  if (n == 0)
    return 1;

  ll res = pow(x, n / 2, mod);

  res = (res * res) % mod;
  if (n % 2)
    res = (res * x) % mod;

  return res;
}
ll _gcd(ll a, ll b) {
  if (a == 0)
    return b;
  else
    return _gcd(b % a, a);
}
// s.erase(s.find(2)) where s={1,2,3,3,2};
}; // namespace Rahul

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

  int n;
  cin >> n;

  string s;
  cin >> s;
  unordered_map<char, char> cn;
  for (char i = 'A'; i < 'Z'; i++) {
    cn[i] = i + 1;
  }
  cn['Z'] = 'A';

  for (int i = 0; i < s.size(); i++) {
    int o = n - 1;
    char c = cn[s[i]];
    while (o--) {
      c = cn[c];
    }
    cout << c;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define se second
#define mp make_pair
#define fi first
#define del(a, vec)                                                            \
  vec.erase(std::remove(vec.begin(), vec.end(), a), vec.end());
#define search(f, l, v) binary_search(f, l, v)
#define iter(a, b) vector<int>::iterator a, b
#define lower(v, num) lower_bound(v.begin(), v.end(), num);
#define upper(v, num) upper_bound(v.begin(), v.end(), num);
#define removecopy(a) unique(a.begin(), a.end());
#define ll long long int
namespace Rahul {
bool isPrime(int n) {
  if (n <= 1)
    return false;
  if (n <= 3)
    return true;
  if (n % 2 == 0 || n % 3 == 0)
    return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0)
      return false;
  return true;
}
ll pow(ll x, ll n, ll mod) { // calculate x^n
  if (n == 0)
    return 1;

  ll res = pow(x, n / 2, mod);

  res = (res * res) % mod;
  if (n % 2)
    res = (res * x) % mod;

  return res;
}
ll _gcd(ll a, ll b) {
  if (a == 0)
    return b;
  else
    return _gcd(b % a, a);
}
// s.erase(s.find(2)) where s={1,2,3,3,2};
}; // namespace Rahul

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

  int n;
  cin >> n;

  string s;
  cin >> s;
  unordered_map<char, char> cn;
  for (char i = 'A'; i < 'Z'; i++) {
    cn[i] = i + 1;
  }
  cn['Z'] = 'A';

  for (int i = 0; i < s.size(); i++) {
    int o = n;
    char c = s[i];
    while (o--) {
      c = cn[c];
    }
    cout << c;
  }
}