Problem p03874 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 55;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int N = 8;
const string s = "FESTIVAL";
ll n;

int main() {
  cin >> n;
  int t = 1, B = 0, l = 0;
  int flag = 2;
  vl dp(N + 1), a, c;
  dp[0] = 1;
  while (1) {
    vl DP = dp;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < t; j++)
        DP[i + 1] += DP[i];
    if (DP[N] > n)
      break;
    dp = DP;
    a.push_back(DP[N - 1]);
    c.push_back(t);
    l += t * N;
    if (flag) {
      flag--;
      continue;
    }
    if (B % 6 < 5)
      t++;
    B++;
  }
  while (t > 0) {
    vl DP = dp;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < t; j++)
        DP[i + 1] += DP[i];
    if (DP[N] > n) {
      t--;
      continue;
    }
    dp = DP;
    l += N * t;
    a.push_back(DP[N - 1]);
    c.push_back(t);
  }
  n -= dp[N];
  int S = a.size();
  vl b(S);
  while (n) {
    for (int i = S - 1; i >= 0; i--)
      if (a[i] <= n) {
        n -= a[i];
        b[i]++;
        l++;
      }
  }
  assert(l <= 5000);
  for (int i = 0; i < S; i++) {
    for (int j = 0; j < N; j++)
      for (int k = 0; k < c[i]; k++)
        cout << s[j];
    for (int j = 0; j < b[i]; j++)
      cout << 'L';
  }
  cout << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 55;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int N = 8;
const string s = "FESTIVAL";
ll n;

int main() {
  cin >> n;
  int t = 1, B = 0, l = 0;
  bool flag = 1;
  vl dp(N + 1), a, c;
  dp[0] = 1;
  while (1) {
    vl DP = dp;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < t; j++)
        DP[i + 1] += DP[i];
    if (DP[N] > n)
      break;
    dp = DP;
    a.push_back(DP[N - 1]);
    c.push_back(t);
    l += t * N;
    if (flag) {
      flag = 0;
      continue;
    }
    if (B % 6 < 5)
      t++;
    B++;
  }
  while (t > 0) {
    vl DP = dp;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < t; j++)
        DP[i + 1] += DP[i];
    if (DP[N] > n) {
      t--;
      continue;
    }
    dp = DP;
    l += N * t;
    a.push_back(DP[N - 1]);
    c.push_back(t);
  }
  n -= dp[N];
  int S = a.size();
  vl b(S);
  while (n) {
    for (int i = S - 1; i >= 0; i--)
      if (a[i] <= n) {
        n -= a[i];
        b[i]++;
        l++;
      }
  }
  assert(l <= 5000);
  for (int i = 0; i < S; i++) {
    for (int j = 0; j < N; j++)
      for (int k = 0; k < c[i]; k++)
        cout << s[j];
    for (int j = 0; j < b[i]; j++)
      cout << 'L';
  }
  cout << endl;
}