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

#include <bits/stdc++.h>
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
#define ll long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
#define mod (ll)(1e9 + 7)
#define inf (ll)(3e18 + 7)
#define pi (double)acos(-1.0)
#define P pair<int, int>
#define PiP pair<int, pair<int, int>>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;

int d, score;
vector<int> c(26);
vector<vector<int>> s(400, vector<int>(26)), pos(26);

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

int main() {
  cin >> d;
  rep(i, 26) cin >> c[i];
  rep(i, d) rep(j, 26) cin >> s[i][j];
  //-----code------//
  vector<int> t, pos(26, 0);
  rep(i, d) {
    int max_score = -mod;
    int best_j = -1;
    rep(j, 26) {
      t.push_back(j);
      int score = get_score(t);
      if (max_score < score) {
        best_j = j;
        max_score = score;
      }
      t.pop_back();
    }
    t.push_back(best_j);
  }
  /*while(clock() < 1950000){
      int D = rand() % d, q = rand() % 26;
      int old = t[D], olds = get_score(t);
      t[D] = q;
      if(get_score(t) < olds)t[D] = old;
  }*/
  rep(i, d) cout << t[i] + 1 << endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
#define ll long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
#define mod (ll)(1e9 + 7)
#define inf (ll)(3e18 + 7)
#define pi (double)acos(-1.0)
#define P pair<int, int>
#define PiP pair<int, pair<int, int>>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;

int d, score;
vector<int> c(26);
vector<vector<int>> s(400, vector<int>(26)), pos(26);

int get_score(vector<int> t) {
  vector<int> pos(26, 0);
  int ans = 0;
  rep(i, t.size()) {
    int l = i + 1 - pos[t[i]];
    ans -= (l * (l - 1) / 2) * c[t[i]];
    ans += s[i][t[i]];
    pos[t[i]] = i + 1;
  }
  rep(i, 26) {
    int l = t.size() + 1 - pos[i];
    ans -= (l * (l - 1) / 2) * c[i];
  }
  return ans;
}

int main() {
  cin >> d;
  rep(i, 26) cin >> c[i];
  rep(i, d) rep(j, 26) cin >> s[i][j];
  //-----code------//
  vector<int> t, pos(26, 0);
  rep(i, d) {
    int max_score = 0;
    int best_j = -1;
    rep(j, 26) {
      t.push_back(j);
      int score = get_score(t);
      if (max_score < score) {
        best_j = j;
        max_score = score;
      }
      t.pop_back();
    }
    t.push_back(best_j);
  }
  /*while(clock() < 1950000){
      int D = rand() % d, q = rand() % 26;
      int old = t[D], olds = get_score(t);
      t[D] = q;
      if(get_score(t) < olds)t[D] = old;
  }*/
  rep(i, d) cout << t[i] + 1 << endl;
}