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

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

#define dump(...)                                                              \\
  DUMPOUT << "  ";                                                             \\
  DUMPOUT << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]"   \\
          << std::endl;                                                        \\
  DUMPOUT << "    ";                                                           \\
  dump_func(__VA_ARGS__)
#define PI 3.14159265358979323846
#define EPS 1e-10
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(j) (j).begin(), (j).end()
#define SZ(j) ((int)(j).size())

int D = 365;
const int T = 26;

vector<int> c(T);
vector<vector<int>> s(D, vector<int>(T));

long long compute_score(vector<int> out) {
  long long score = 0;
  vector<int> last(T, 0);
  REP(d, (int)out.size()) {
    last[out[d] - 1] = d + 1;
    REP(i, T) { score -= (long long)(d + 1 - last[i]) * c[i]; }
    score += s[d][out[d] - 1];

    // cout << score << endl;
  }

  return score;
}

vector<int> solve() {
  vector<int> out;
  REP(_, D) {
    int best_i = 1;
    long long max_score = -(1e18);
    FOR(i, 1, T + 1) {
      out.emplace_back(i);
      long long score = compute_score(out);
      if (max_score < score) {
        max_score = score;
        best_i = i;
      }

      out.pop_back();
    }
    out.emplace_back(best_i);
  }

  return out;
}

void test_score() {
  vector<int> t(D);
  REP(i, D) cin >> t[i];
  compute_score(t);
}

int main(int argc, char const *argv[]) {
  int d_;
  cin >> d_;
  D = d_;

  REP(i, T) cin >> c[i];
  REP(i, D) REP(j, T) cin >> s[i][j];

  vector<int> out = solve();
  assert(out.size() == D);
  for (int t : solve()) {
    cout << t << endl;
  }

  return 0;
}


Error: -6
a0904c05-9a9c-468a-b834-037db5316069.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02618/C++/s208201289.cpp:70: int main(int, const char**): Assertion `out.size() == D' failed.


Fixed submission:

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

#define dump(...)                                                              \\
  DUMPOUT << "  ";                                                             \\
  DUMPOUT << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]"   \\
          << std::endl;                                                        \\
  DUMPOUT << "    ";                                                           \\
  dump_func(__VA_ARGS__)
#define PI 3.14159265358979323846
#define EPS 1e-10
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(j) (j).begin(), (j).end()
#define SZ(j) ((int)(j).size())

int D = 365;
const int T = 26;

vector<int> c(T);
vector<vector<int>> s(D, vector<int>(T));

long long compute_score(vector<int> out) {
  long long score = 0;
  vector<int> last(T, 0);
  REP(d, (int)out.size()) {
    last[out[d] - 1] = d + 1;
    REP(i, T) { score -= (long long)(d + 1 - last[i]) * c[i]; }
    score += s[d][out[d] - 1];

    // cout << score << endl;
  }

  return score;
}

vector<int> solve() {
  vector<int> out;
  REP(_, D) {
    int best_i = 1;
    long long max_score = -(1e18);
    FOR(i, 1, T + 1) {
      out.emplace_back(i);
      long long score = compute_score(out);
      if (max_score < score) {
        max_score = score;
        best_i = i;
      }

      out.pop_back();
    }
  }

  return out;
}

void test_score() {
  vector<int> t(D);
  REP(i, D) cin >> t[i];
  compute_score(t);
}

int main(int argc, char const *argv[]) {
  int d_;
  cin >> d_;
  D = d_;

  REP(i, T) cin >> c[i];
  REP(i, D) REP(j, T) cin >> s[i][j];

  vector<int> out = solve();
  assert(out.size() == D);
  for (int t : solve()) {
    cout << t << endl;
  }

  return 0;
}