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

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

ll calc_score(ll D, const vector<ll> &c, const vector<vector<ll>> &s,
              const vector<ll> &t) {
  vector<ll> last(26, -1);
  ll score = 0;
  REP(d, D) {
    ll i = t[d];
    score += s[d][i];
    last[i] = d;
    REP(j, 26) { score -= c[j] * (d - last[j]); }
  }
  return score;
}

ll area(ll D, ll d, const vector<ll> &t, ll target) {
  ll l = -1;
  for (int i = d - 1; i >= 0; i--) {
    if (t[i] == target) {
      l = i;
      break;
    }
  }
  ll r = D;
  FOR(i, d + 1, D) {
    if (t[i] == target) {
      r = i;
      break;
    }
  }
  ll x = r - d;
  ll y = d - l;
  return x * y;
}

ll calc_diff(ll D, ll pre, ll next, const vector<ll> &c,
             const vector<vector<ll>> &s, ll d, const vector<ll> &t) {
  ll diff = s[d][next] - s[d][pre];
  diff += c[next] * area(D, d, t, next);
  diff -= c[pre] * area(D, d, t, pre);
  return diff;
}

void solve(ll D, vector<ll> c, vector<vector<ll>> s) {
  vector<ll> t(D);
  REP(d, D) {
    ll m = LLONG_MIN;
    ll cur = 0;
    REP(i, c.size()) {
      t[d] = i;
      ll score = calc_score(d + 1, c, s, t);
      if (score > m) {
        m = score;
        cur = i;
      }
    }
    t[d] = cur;
  }
  REP(d, D) { cout << t[d] + 1 << "\\n"; }
}

int main() {
  ll D;
  scanf("%lld", &D);
  vector<ll> c(26);
  for (int i = 0; i < 26; i++) {
    scanf("%lld", &c[i]);
  }
  vector<vector<ll>> s(D, vector<ll>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      scanf("%lld", &s[i][j]);
    }
  }
  solve(D, move(c), move(s));
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

ll calc_score(ll D, const vector<ll> &c, const vector<vector<ll>> &s,
              const vector<ll> &t) {
  vector<ll> last(26, 0);
  ll score = 0;
  REP(d, D) {
    ll i = t[d] - 1;
    score += s[d][i];
    last[i] = d + 1;
    REP(j, 26) { score -= c[j] * (d + 1 - last[j]); }
  }
  return score;
}

ll calc_diff(ll D, ll pre, ll next, const vector<ll> &c,
             const vector<vector<ll>> &s, ll d, const vector<ll> &t) {
  ll diff = s[d - 1][next] - s[d - 1][pre];
  {
    ll l = 0;
    for (int i = d - 1; i >= 1; i--) {
      if (t[i - 1] - 1 == next) {
        l = i;
        break;
      }
    }
    ll r = D + 1;
    FOR(i, d + 1, D + 1) {
      if (t[i - 1] - 1 == next) {
        r = i;
        break;
      }
    }
    ll x = r - d;
    ll y = d - l;
    diff += c[next] * x * y;
  }
  {
    ll l = 0;
    for (int i = d - 1; i >= 1; i--) {
      if (t[i - 1] - 1 == pre) {
        l = i;
        break;
      }
    }
    ll r = D + 1;
    FOR(i, d + 1, D + 1) {
      if (t[i - 1] - 1 == pre) {
        r = i;
        break;
      }
    }
    ll x = r - d;
    ll y = d - l;
    diff -= c[pre] * x * y;
  }
  return diff;
}

void solve(ll D, vector<ll> c, vector<vector<ll>> s) {
  vector<ll> t(D);
  FOR(d, 1, D + 1) {
    ll m = 0;
    ll cur = 0;
    REP(i, c.size()) {
      t[d - 1] = i + 1;
      ll score = calc_score(d, c, s, t);
      if (score > m) {
        m = score;
        cur = i + 1;
      }
    }
    t[d - 1] = cur;
  }
  REP(d, D) { cout << t[d] << endl; }
}

int main() {
  ll D;
  scanf("%lld", &D);
  vector<ll> c(26);
  for (int i = 0; i < 26; i++) {
    scanf("%lld", &c[i]);
  }
  vector<vector<ll>> s(D, vector<ll>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      scanf("%lld", &s[i][j]);
    }
  }
  solve(D, move(c), move(s));
  return 0;
}