Problem p02866 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <vector>
#define mp make_pair
#define pb push_back
#define p push
#define FOR(a, c) for (int a = 0; a < c; a++)
#define FORR(el, vecc) for (auto &el : vecc)
#define ll long long int
#define abs(x) (x < 0 ? (-x) : x)
#define getI(a) scanf("%d", &a)
#define getII(a, b) scanf("%d %d", &a, &b)
#define getIII(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define getL(a) scanf("%lld", &a)
#define getLL(a, b) scanf("%lld %lld", &a, &b)
#define getLLL(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define BEND(c) (c).begin(), (c).end()
#define BEND2(c) (c).begin(), (c).end(), greater<int>()
#define fi first
#define se second
#define PI 3.1415926535897932384626
#define getS(a) scanf("%s", a)
#define pfi(a) printf("%d", a);
#define pfii(a, b) printf("%d%d", a, b);
#define pfl(a) printf("%lld", a);
#define pfll(a, b) printf("%lld%lld", a, b);
#define pfd(a) printf("%.6lf\n", a);
#define SIZE

#define sag (sol | 1)
#define sol (root << 1)
#define ort (bas + son) / 2
#define N (int)(1e5 + 10)

using namespace std;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<long long> vl;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef vector<vector<pair<long long, long long>>> vvpl;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;

long long fast_exp(long long n, long long k) {
  ll t = n;
  if (k == 1)
    return n;
  k--;
  while (k--) {
    n = (n * t) % 998244353;
  }
  return n;
}
/*ios_base::sync_with_stdio(false);cin.tie(0);*/
int main() {
  ll n;
  cin >> n;
  vl vec(n);
  map<ll, ll> mm;
  for (int i = 0; i < n; ++i) {
    cin >> vec[i];
    mm[vec[i]]++;
  }
  if (vec[0] != 0) {
    cout << 0;
    return 0;
  }
  sort(BEND2(vec));
  if (mm[0] != 1) {
    cout << 0;
    return 0;
  }
  ll res = 1;
  for (int j = 1; j <= vec[0]; ++j) {
    res = (res * ((fast_exp(mm[j - 1], mm[j])) % 998244353) % 998244353) %
          998244353;
    res = res % 998244353;
  }
  cout << res;
}

Fixed submission:
#include <bits/stdc++.h>

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <vector>
#define mp make_pair
#define pb push_back
#define p push
#define FOR(a, c) for (int a = 0; a < c; a++)
#define FORR(el, vecc) for (auto &el : vecc)
#define ll long long int
#define abs(x) (x < 0 ? (-x) : x)
#define getI(a) scanf("%d", &a)
#define getII(a, b) scanf("%d %d", &a, &b)
#define getIII(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define getL(a) scanf("%lld", &a)
#define getLL(a, b) scanf("%lld %lld", &a, &b)
#define getLLL(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define BEND(c) (c).begin(), (c).end()
#define BEND2(c) (c).begin(), (c).end(), greater<int>()
#define fi first
#define se second
#define PI 3.1415926535897932384626
#define getS(a) scanf("%s", a)
#define pfi(a) printf("%d", a);
#define pfii(a, b) printf("%d%d", a, b);
#define pfl(a) printf("%lld", a);
#define pfll(a, b) printf("%lld%lld", a, b);
#define pfd(a) printf("%.6lf\n", a);
#define SIZE

#define sag (sol | 1)
#define sol (root << 1)
#define ort (bas + son) / 2
#define N (int)(1e5 + 10)

using namespace std;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<long long> vl;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef vector<vector<pair<long long, long long>>> vvpl;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;

long long fast_exp(long long n, long long k) {
  ll t = n;

  while (k > 1) {
    k--;
    n = (n * t) % 998244353;
  }
  return n;
}
/*ios_base::sync_with_stdio(false);cin.tie(0);*/
int main() {
  ll n;
  cin >> n;
  vl vec(n);
  map<ll, ll> mm;
  for (int i = 0; i < n; ++i) {
    cin >> vec[i];
    mm[vec[i]]++;
  }
  if (vec[0] != 0) {
    cout << 0;
    return 0;
  }
  sort(BEND2(vec));
  if (mm[0] != 1) {
    cout << 0;
    return 0;
  }
  ll res = 1;
  for (int j = 1; j <= vec[0]; ++j) {
    res = (res * ((fast_exp(mm[j - 1], mm[j])) % 998244353) % 998244353) %
          998244353;
    res = res % 998244353;
  }
  cout << res;
}