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

// Author: AnandRaj doubleux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;

#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define test()                                                                 \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define all(v) v.begin(), v.end()
#define prinp(p) cout << p.first << " " << p.second << endl
#define prinv(V)                                                               \\
  for (auto v : V)                                                             \\
    cout << v << " ";                                                          \\
  cout << endl
#define take(V, f, n)                                                          \\
  for (int in = f; in < f + n; in++)                                           \\
  cin >> V[in]
#define what(x) cerr << #x << " = " << x << endl
#define KStest()                                                               \\
  int t, t1;                                                                   \\
  cin >> t;                                                                    \\
  t1 = t;                                                                      \\
  while (t--)
#define KScout cout << "Case #" << t1 - t << ": "

const int MOD = 1e9 + 7, MAX = 1e5 + 5;
const ll INF = 1e15 + 5;
/////////////////FastExp///////////////////
ll powN(ll a, ll p) {
  if (p == 0)
    return 1;
  ll z = powN(a, p / 2);
  z = (z * z) % MOD;
  if (p % 2)
    z = (z * a) % MOD;
  return z;
}
/////////////////FastExp///////////////////
///////////////////PnC/////////////////////
vl Fac(MAX), Inv(MAX);
void CalcFac() {
  Fac[0] = Inv[0] = 1;
  for (int i = 1; i < MAX; i++) {
    Fac[i] = (Fac[i - 1] * i) % MOD;
    Inv[i] = powN(Fac[i], MOD - 2);
  }
}

ll NCR(int n, int r) {
  if (r > n)
    return 0;
  return (((Fac[n] * Inv[r]) % MOD) * Inv[n - r]) % MOD;
}
///////////////////PnC/////////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vi MinDiv(MAX);
void Sieve() {
  is_prime[0] = is_prime[1] = false;
  int i, j;
  for (i = 2; i * i <= MAX; i++) {
    if (is_prime[i]) {
      MinDiv[i] = i;
      for (j = i * i; j <= MAX; j += i) {
        is_prime[j] = false;
        MinDiv[j] = i;
      }
    }
  }
  for (int i = 2; i <= MAX; i++)
    if (is_prime[i])
      MinDiv[i] = i;
}
//////////////////Sieve////////////////////

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vi C(26);
vvi S(366, vi(26));
int D;
int score(vi t) {
  int Sat = 0;
  vi L(26);
  for (int i = 1; i <= D; i++) {
    Sat += S[i][t[i]];
    L[t[i]] = i;

    for (int c = 0; c < 26; c++) {
      Sat -= C[c] * (i - L[c]);
    }
  }
  return Sat;
}

int main() {
  cin >> D;
  take(C, 0, 26);
  for (int i = 1; i <= D; i++) {
    take(S[i], 0, 26);
  }
  int maxscore = -1000000000;
  vi bestT(D + 1);
  for (int times = 0; times < 100; times++) {
    vi T(D + 1);
    for (int i = 1; i <= D; i++) {
      T[i] = rng() % 26;
    }
    int thiscore = score(T);
    if (thiscore > maxscore) {
      maxscore = thiscore;
      bestT = T;
    }
  }

  for (int i = 1; i <= D; i++) {
    cout << bestT[i] + 1 << endl;
  }
  // cout<<maxscore<<endl;
}

Error: WA

Fixed submission:

// Author: AnandRaj doubleux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;

#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define test()                                                                 \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define all(v) v.begin(), v.end()
#define prinp(p) cout << p.first << " " << p.second << endl
#define prinv(V)                                                               \\
  for (auto v : V)                                                             \\
    cout << v << " ";                                                          \\
  cout << endl
#define take(V, f, n)                                                          \\
  for (int in = f; in < f + n; in++)                                           \\
  cin >> V[in]
#define what(x) cerr << #x << " = " << x << endl
#define KStest()                                                               \\
  int t, t1;                                                                   \\
  cin >> t;                                                                    \\
  t1 = t;                                                                      \\
  while (t--)
#define KScout cout << "Case #" << t1 - t << ": "

const int MOD = 1e9 + 7, MAX = 1e5 + 5;
const ll INF = 1e18 + 5;
/////////////////FastExp///////////////////
ll powN(ll a, ll p) {
  if (p == 0)
    return 1;
  ll z = powN(a, p / 2);
  z = (z * z) % MOD;
  if (p % 2)
    z = (z * a) % MOD;
  return z;
}
/////////////////FastExp///////////////////
///////////////////PnC/////////////////////
vl Fac(MAX), Inv(MAX);
void CalcFac() {
  Fac[0] = Inv[0] = 1;
  for (int i = 1; i < MAX; i++) {
    Fac[i] = (Fac[i - 1] * i) % MOD;
    Inv[i] = powN(Fac[i], MOD - 2);
  }
}

ll NCR(int n, int r) {
  if (r > n)
    return 0;
  return (((Fac[n] * Inv[r]) % MOD) * Inv[n - r]) % MOD;
}
///////////////////PnC/////////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vi MinDiv(MAX);
void Sieve() {
  is_prime[0] = is_prime[1] = false;
  int i, j;
  for (i = 2; i * i <= MAX; i++) {
    if (is_prime[i]) {
      MinDiv[i] = i;
      for (j = i * i; j <= MAX; j += i) {
        is_prime[j] = false;
        MinDiv[j] = i;
      }
    }
  }
  for (int i = 2; i <= MAX; i++)
    if (is_prime[i])
      MinDiv[i] = i;
}
//////////////////Sieve////////////////////

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vi C(26);
vvi S(366, vi(26));
int D;
int score(vi t) {
  int Sat = 0;
  vi L(26);
  for (int i = 1; i <= D; i++) {
    // cout<<Sat<<endl;
    Sat += S[i][t[i]];
    L[t[i]] = i;

    for (int c = 0; c < 26; c++) {
      Sat -= C[c] * (i - L[c]);
    }
  }
  return Sat;
}

int main() {
  cin >> D;
  take(C, 0, 26);
  for (int i = 1; i <= D; i++) {
    take(S[i], 0, 26);
  }
  int maxscore = 0;
  vi bestT;
  for (int times = 0; times < 100; times++) {
    vi T(D + 1);
    for (int i = 1; i <= D; i++) {
      T[i] = rng() % 26;
    }
    int thiscore = score(T);
    if (thiscore > maxscore) {
      maxscore = thiscore;
      bestT = T;
    }
  }

  for (int i = 1; i <= D; i++) {
    cout << bestT[i] + 1 << endl;
  }
  // cout<<maxscore<<endl;
}