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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
#define ll long long

int main() {
  ll d;
  cin >> d;
  ////////
  vector<vector<ll>> s(365, vector<ll>(26, 0));
  vector<int> c(26);
  vector<ll> t(d, 1);
  for (int i = 0; i < 26; i++)
    cin >> c[i];
  for (int i = 0; i < d; i++) {
    ll tmp = 0;
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
      if (tmp < s[i][j]) {
        tmp = s[i][j];
        t[i] = j + 1;
      }
    }
  }

  /////////////////
  /*
  for(int i = 0; i < d; i++) {
      t[i] = i+1;
  }
  */
  // for(int i = 0; i < d; i++) cin >> t[i];
  ll mx_v = 0;
  vector<ll> swap_set;
  vector<pair<int, int>> p(d);
  for (int i = 0; i < d; i++) {
    mx_v = -1;
    int ni = i, nj = 0;
    for (int j = 0; j < 26; j++) {
      if (s[i][j] > mx_v) {
        mx_v = s[i][j];
        ni = i;
        nj = j;
      }
    }
    swap_set.push_back(mx_v);
    p[i] = make_pair(ni, nj);
    // p.push_back(make_pair(ni, nj));
  }

  ///////////////
  ll m;
  m = d;
  // cin >> m;
  vector<pair<int, int>> dq(m);
  for (int i = 0; i < m; i++) {
    // cin >> dq[i].first >> dq[i].second;
    dq[i].first = p[i].first + 1;
    dq[i].second = p[i].second + 1;
    // cout << dq[i].first << " " << dq[i].second << endl;
  }
  vector<ll> ans(d, 0);
  ll v = 0;
  // ll tmp = 0;
  map<ll, ll> mp;
  priority_queue<ll> que;
  vector<vector<ll>> list(m, vector<ll>(d, 1));
  // int num = 0;
  for (int k = 0; k < m; k++) {
    //
    // tmp = t[dq[k].first-1];
    // cout << dq[k].first-1 << " " << t[dq[k].first-1] << endl;
    t[dq[k].first - 1] = dq[k].second;

    /////////////////////
    vector<ll> last(26, 0);
    for (int i = 0; i < d; i++) {
      // if(t[i]-1 >= 26) cout << "t: " << t[i]-1 << endl;
      v += s[i][t[i] - 1]; //-1
      // v += s[t[i]-1][];
      // v +=
      last[t[i] - 1] = i + 1; //-1
      for (int j = 0; j < 26; j++) {
        v -= c[j] * ((i + 1) - last[j]);
      }
    }
    // cout << v << endl;
    que.push(v);
    mp[v] = k;
    for (int i = 0; i < d; i++) {
      // list[k].push_back(t[i]);
      list[k][i] = t[i];
      // cout << t[i] << endl;
    }
    v = 0;
  }

  // cout << mp[que.top()] << endl;
  // cout << list[0].size() << endl;
  // cout << m << endl;
  ll tmp = que.top();
  for (int i = 0; i < m; i++) {
    // cout << list[mp[que.top()]][i] << endl;
    cout << list[mp[tmp]][i] << endl;
    // cout << que.top() << endl;
    // que.pop();
    /*
    cout << "i: " << i << endl;
    for(int j = 0; j < list[i].size(); j++) {
        cout << list[i][j]+1 << endl;
    }
    */
  }

  return 0;
}

Error: -6
free(): invalid pointer


Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
#define ll long long

int main() {
  ll d;
  cin >> d;
  ////////
  vector<vector<ll>> s(365, vector<ll>(26, 0));
  vector<int> c(26);
  vector<ll> t(d, 1);
  for (int i = 0; i < 26; i++)
    cin >> c[i];
  for (int i = 0; i < d; i++) {
    ll tmp = 0;
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
      if (tmp < s[i][j]) {
        tmp = s[i][j];
        t[i] = j;
      }
    }
  }

  /////////////////
  /*
  for(int i = 0; i < d; i++) {
      t[i] = i+1;
  }
  */
  // for(int i = 0; i < d; i++) cin >> t[i];
  ll mx_v = 0;
  vector<ll> swap_set;
  vector<pair<int, int>> p(d);
  for (int i = 0; i < d; i++) {
    mx_v = -1;
    int ni = i, nj = 0;
    for (int j = 0; j < 26; j++) {
      if (s[i][j] > mx_v) {
        mx_v = s[i][j];
        ni = i;
        nj = j;
      }
    }
    swap_set.push_back(mx_v);
    p[i] = make_pair(ni, nj);
    // p.push_back(make_pair(ni, nj));
  }

  ///////////////
  ll m;
  m = d;
  // cin >> m;
  vector<pair<int, int>> dq(m);
  for (int i = 0; i < m; i++) {
    // cin >> dq[i].first >> dq[i].second;
    dq[i].first = p[i].first + 1;
    dq[i].second = p[i].second + 1;
    // cout << dq[i].first << " " << dq[i].second << endl;
  }
  vector<ll> ans(d, 0);
  ll v = 0;
  // ll tmp = 0;
  map<ll, ll> mp;
  priority_queue<ll> que;
  vector<vector<ll>> list(m, vector<ll>(d, 1));
  // int num = 0;
  for (int k = 0; k < m; k++) {
    //
    // tmp = t[dq[k].first-1];
    // cout << dq[k].first-1 << " " << t[dq[k].first-1] << endl;
    t[dq[k].first - 1] = dq[k].second - 1;

    /////////////////////
    vector<ll> last(26, 0);
    for (int i = 0; i < d; i++) {
      // if(t[i]-1 >= 26) cout << "t: " << t[i]-1 << endl;
      v += s[i][t[i] - 1]; //-1
      // v += s[t[i]-1][];
      // v +=
      last[t[i] - 1] = i + 1; //-1
      for (int j = 0; j < 26; j++) {
        v -= c[j] * ((i + 1) - last[j]);
      }
    }
    // cout << v << endl;
    que.push(v);
    mp[v] = k;
    for (int i = 0; i < d; i++) {
      // list[k].push_back(t[i]);
      list[k][i] = t[i];
      // cout << t[i] << endl;
    }
    v = 0;
  }

  // cout << mp[que.top()] << endl;
  // cout << list[0].size() << endl;
  // cout << m << endl;
  ll tmp = que.top();
  for (int i = 0; i < m; i++) {
    // cout << list[mp[que.top()]][i] << endl;
    cout << list[mp[tmp]][i] + 1 << endl;
    // cout << que.top() << endl;
    // que.pop();
    /*
    cout << "i: " << i << endl;
    for(int j = 0; j < list[i].size(); j++) {
        cout << list[i][j]+1 << endl;
    }
    */
  }

  return 0;
}