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

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int(i) = 0; i < (n); i++)
#define rrep(i, n) for (int(i) = 1; i <= (n); i++)
#define REP(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\\n"
#define yorn(f) puts((f) ? "Yes" : "No")
#define YORN(f) puts((f) ? "YES" : "NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; };
int lcm(int a, int b) { return a / gcd(a, b) * b; };
int mod(int a, int b) { return (a + b - 1) / b; };
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
};
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
};

int D;
vector<int> c(26);
vector<vector<int>> s(365, vector<int>(26));

int evaluate(vector<int> &t) {
  int score = 0;
  vector<int> last(26, -1);
  rep(i, t.size()) {
    score += s[i][t[i]];
    last[t[i]] = i;
    rep(j, 26) score -= c[j] * (i - last[j]);
  }
  return score;
}

signed main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  // cout << fixed << setprecision(15);

  cin >> D;
  rep(i, 26) {
    cin >> c[i];
    c[i]--;
  }
  rep(i, D) { rep(j, 26) cin >> s[i][j]; }

  vector<int> ans;
  rep(i, D) {
    int max_score = LLONG_MIN;
    int type = -1;
    rep(j, 26) {
      ans.push_back(j);
      int score = evaluate(ans);
      if (max_score < score) {
        max_score = score;
        type = j;
      }
      ans.pop_back();
    }
    ans.push_back(type);
  }
  rep(i, ans.size()) cout << ans[i] + 1 << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int(i) = 0; i < (n); i++)
#define rrep(i, n) for (int(i) = 1; i <= (n); i++)
#define REP(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\\n"
#define yorn(f) puts((f) ? "Yes" : "No")
#define YORN(f) puts((f) ? "YES" : "NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; };
int lcm(int a, int b) { return a / gcd(a, b) * b; };
int mod(int a, int b) { return (a + b - 1) / b; };
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
};
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
};

int D;
vector<int> c(26);
vector<vector<int>> s(365, vector<int>(26));
vector<int> last(26);

void input() {
  cin >> D;
  rep(i, 26) cin >> c[i];
  rep(i, D) { rep(j, 26) cin >> s[i][j]; }
}

int calc_score(vector<int> &t) {
  int score = 0;
  rep(i, t.size()) {
    last[t[i] - 1] = i + 1;
    rep(j, 26) { score -= (i + 1 - last[j]) * c[j]; }
    score += s[i][t[i] - 1];
  }
  return score;
}

signed main() {
  // cout << fixed << setprecision(15);

  input();
  vector<int> res;
  rep(i, D) {
    int maxscore = LONG_MIN;
    int bestId = 0;
    rep(j, 26) {
      res.push_back(j);
      int now = calc_score(res);
      if (maxscore < now) {
        maxscore = now;
        bestId = j;
      }
      res.pop_back();
    }
    res.push_back(bestId);
  }
  rep(i, res.size()) { cout << res[i] << endl; }
  return 0;
}