alexjercan/bugnet huggingface dataset:
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  int D;
  cin >> D;
  D = 365;
  vector<ll> c(26);
  vector<ll> d(26);
  ll sumc = 0;
  vector<vector<ll>> s(D, vector<ll>(26));
  for (int i = 0; i < 26; i++) {
    cin >> c.at(i);
    c.at(i) = 0;
    sumc += c.at(i);
  }
  for (int i = 0; i < 365; i++) {
    for (int j = 0; j < 26; j++) {
      s.at(i).at(j) = 0;
      cin >> s.at(i).at(j);
    }
  }
  ll dp[400][30];
  for (int i = 1; i <= D; i++) {
    if (i == 1) {
      ll rock = 0;
      for (int j = 1; j <= 26; j++) {
        rock = max(rock, s.at(0).at(j - 1) - (sumc - c.at(j - 1)));
      }
      for (int j = 1; j <= 26; j++) {
        if (s.at(0).at(j - 1) - (sumc - c.at(j - 1)) == rock) {
          d.at(j - 1) = i;
          cout << j << endl;
          break;
        }
      }
      for (int j = 1; j <= 26; j++) {
        dp[1][j] = s.at(0).at(j - 1) - (sumc - c.at(j - 1));
      }
    } else {
      for (int j = 1; j <= 26; j++) {
        dp[i][j] = dp[i - 1][j];
        for (int k = 1; k <= 26; k++) {
          dp[i][j] -= (i - d.at(k - 1)) * c.at(k - 1);
          if (d.at(k - 1) + 1 == i) {
            dp[i][j] += c.at(k - 1);
          }
        }
      }
      ll ans = 0;
      for (int j = 1; j <= 26; j++) {
        ans = max(ans, dp[i][j]);
      }
      for (int j = 1; j <= 26; j++) {
        if (ans == dp[i][j]) {
          d.at(j - 1) = i;
          cout << j << endl;
          break;
        }
      }
    }
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  int D;
  cin >> D;
  vector<ll> c(26);
  ll maximum = 0, memo;
  vector<vector<ll>> s(365, vector<ll>(26));
  for (int i = 0; i < 26; i++) {
    cin >> c.at(i);
    maximum = max(maximum, c.at(i));
    if (maximum == c.at(i)) {
      memo = i;
    }
  }
  for (int i = 0; i < 365; i++) {
    ll M = 0;
    for (int j = 0; j < 26; j++) {
      cin >> s.at(i).at(j);
      M = max(M, s.at(i).at(j));
    }
    ll rock = M / maximum;
    if (M % maximum != 0) {
      rock++;
    }
    if (i != 0 && i % memo == 0) {
      cout << s.at(i).at(memo) << endl;
    } else {
      cout << M << endl;
    }
  }
}
Problem p02618 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
ll n, s[26], d[365][26], t[365], ans, u[26], q, a, b, c, MAX = -10000000, L,
                                                         A[365];
int main(void) {
  cin >> n;
  for (int i = 0; i < 26; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> d[i][j];
    }
  }

  for (int i = 0; i < n; i++) {
    t[i] = i % 26 + 1;
  }

  q = 1000;
  while (q--) {
    a = rand() % n;
    b = rand() % 26;
    ans = 0;
    for (int i = 0; i < 26; i++)
      u[i] = 0;

    c = t[a];
    t[a] = b + 1;

    for (int i = 0; i < n; i++) {
      ans += d[i][t[i] - 1];
      u[t[i] - 1] = i + 1;
      for (int j = 0; j < 26; j++) {
        ans -= s[j] * (i + 1 - u[j]);
      }
    }
    if (MAX < ans) {
      MAX = ans;
      for (int i = 0; i < n; i++) {
        A[i] = t[i];
      }
    } else
      t[a] = c;
  }

  for (int i = 0; i < n; i++) {
    cout << A[i] << endl;
  }
  // cout<<MAX<<endl;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
ll n, s[26], d[365][26], t[365], ans, u[26], q, a, b, c, MAX = -10000000, L,
                                                         A[365];
int main(void) {
  cin >> n;
  for (int i = 0; i < 26; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> d[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }

  for (int i = 0; i < n; i++) {
    t[i] = i % 26 + 1;
  }

  q = 10000000;
  while (q--) {
    a = rand() % n;
    b = rand() % 26;
    ans = 0;
    for (int i = 0; i < 26; i++)
      u[i] = 0;

    c = t[a];
    t[a] = b + 1;

    for (int i = 0; i < n; i++) {
      ans += d[i][t[i] - 1];
      u[t[i] - 1] = i + 1;
      for (int j = 0; j < 26; j++) {
        ans -= s[j] * (i + 1 - u[j]);
      }
    }
    if (MAX < ans) {
      MAX = ans;
      for (int i = 0; i < n; i++) {
        A[i] = t[i];
      }
    } else
      t[a] = c;
  }

  for (int i = 0; i < n; i++) {
    cout << A[i] << endl;
  }
  // cout<<MAX<<endl;
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

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

int d;
vector<int> c;
vector<vector<int>> s;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int myrand(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  srand(time(nullptr));
  cin >> d;
  c.resize(26);
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
  }
  s.assign(d, vector<int>(26));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }
  vector<int> t;
  for (int i = 0; i < d; i++) {
    int best = 0;
    for (int j = 1; j < 26; j++) {
      if (s[i][j] > s[i][best]) {
        best = j;
      }
    }
    t.push_back(best);
  }
  for (int i = 0; i < 50000; i++) {
    int pos = myrand(0, d - 1), x = myrand(0, 25);
    vector<int> tmp = t;
    tmp[pos] = x;
    if (satisfaction(tmp) > satisfaction(t)) {
      swap(t, tmp);
    }
  }
  for (auto &x : t) {
    cout << x + 1 << '\\n';
  }
  return 0;
}

Error: WA

Fixed submission:

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

int d;
vector<int> c;
vector<vector<int>> s;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int myrand(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  srand(time(nullptr));
  cin >> d;
  c.resize(26);
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
  }
  s.assign(d, vector<int>(26));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }
  vector<int> t;
  for (int i = 0; i < d; i++) {
    int best = i;
    for (int j = 1; j < 26; j++) {
      if (s[i][j] > s[i][best]) {
        best = j;
      }
    }
    t.push_back(best);
  }
  for (int i = 0; i < 50000; i++) {
    int pos = myrand(0, d - 1), x = myrand(0, 25);
    vector<int> tmp = t;
    tmp[pos] = x;
    if (satisfaction(tmp) > satisfaction(t)) {
      swap(t, tmp);
    }
  }
  for (auto &x : t) {
    cout << x + 1 << '\\n';
  }
  return 0;
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
using ll = long long;

int main() {
  int d;
  cin >> d;

  vector<int> c(26 + 1);
  rep(i, 26) cin >> c[i];

  vector<vector<int>> s(d + 1, vector<int>(26 + 1));
  rep(i, d) rep(j, 26) cin >> s[i][j];

  /*vector<int> t(d + 1);
  rep (i, d)
      cin >> t[i];*/

  int score = 0;
  vector<int> ans(d + 1);
  vector<int> last(26 + 1, 0);
  rep(i, d) {
    vector<pair<int, int>> temp(26);
    rep(t, 26) {
      temp[t - 1].second = t;
      temp[t - 1].first = s[i][t] + score;
      rep(j, 26) {
        if (j == t)
          continue;
        temp[t - 1].first -= c[j] * (i - last[j]);
      }
    }
    sort(temp.begin(), temp.end());
    score += temp[26 - 1].first;
    ans[i] = temp[26 - 1].second;
    last[temp[26 - 1].second] = i;
  }

  rep(i, d) cout << ans[i] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
using ll = long long;

int main() {
  int d;
  cin >> d;

  vector<int> c(26 + 1);
  rep(i, 26) cin >> c[i];

  vector<vector<int>> s(d + 1, vector<int>(26 + 1));
  rep(i, d) rep(j, 26) cin >> s[i][j];

  /*vector<int> t(d + 1);
  rep (i, d)
      cin >> t[i];*/

  int score = 0;
  vector<int> ans(d + 1);
  vector<int> last(26 + 1, 0);
  rep(i, d) {
    vector<pair<int, int>> temp(26);
    rep(t, 26) {
      temp[t - 1].second = t;
      temp[t - 1].first = s[i][t] + score;
      rep(j, 26) {
        if (j == t)
          continue;
        temp[t - 1].first -= c[j] * (i - last[j]);
      }
    }
    sort(temp.begin(), temp.end());
    score += temp[26 - 1].first;
    last[i] = temp[26 - 1].second;
    ans[i] = temp[26 - 1].second;
  }

  rep(i, d) cout << ans[i] << endl;
  return 0;
}
Problem p02618 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  auto start = steady_clock::now();

  random_device rnd;

  int D;
  vector<int> cs(26);
  cin >> D;
  for (auto &&c : cs) {
    cin >> c;
  }
  vector<vector<int>> sss(D, vector<int>(26));
  for (auto &&ss : sss) {
    for (auto &&s : ss) {
      cin >> s;
    }
  }

  vector<int> ts(D);
  for (auto &&t : ts) {
    t = rnd() % 26;
  }

  auto calc_score = [&] {
    vector<int> last(26, -1);

    int s = 0;

    for (int d = 0; d < D; d++) {
      s += sss[d][ts[d]];

      last[ts[d]] = d;

      for (int i = 0; i < 26; i++) {
        s -= cs[i] * (d - last[i]);
      }
    }

    // return max(0, 1000000 + s);
    return s;
  };

  auto calc_diff = [&](int d, int q) {
    int p = ts[d];

    ts[d] = q;

    int ret = calc_score();

    ts[d] = p;

    return ret;
  };

  int score = calc_score();

  while (duration_cast<milliseconds>(steady_clock::now() - start).count() <
         1950) {
    for (int d = 0; d < D; d++) {
      for (int q = 0; q < 26; q++) {
        if (ts[d] == q) {
          continue;
        }

        int next_score = calc_diff(d, q);

        if (score < next_score) {
          ts[d] = q;
          score = next_score;
        }
      }
    }
  }

  for (auto &&t : ts) {
    cout << t + 1 << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  auto start = steady_clock::now();

  random_device rnd;

  int D;
  vector<int> cs(26);
  cin >> D;
  for (auto &&c : cs) {
    cin >> c;
  }
  vector<vector<int>> sss(D, vector<int>(26));
  for (auto &&ss : sss) {
    for (auto &&s : ss) {
      cin >> s;
    }
  }

  vector<int> ts(D);
  for (auto &&t : ts) {
    t = rnd() % 26;
  }

  auto calc_score = [&] {
    vector<int> last(26, -1);

    int s = 0;

    for (int d = 0; d < D; d++) {
      s += sss[d][ts[d]];

      last[ts[d]] = d;

      for (int i = 0; i < 26; i++) {
        s -= cs[i] * (d - last[i]);
      }
    }

    // return max(0, 1000000 + s);
    return s;
  };

  auto calc_diff = [&](int d, int q) {
    int p = ts[d];

    ts[d] = q;

    int ret = calc_score();

    ts[d] = p;

    return ret;
  };

  int score = calc_score();

  while (duration_cast<milliseconds>(steady_clock::now() - start).count() <
         1970) {
    for (int d = 0; d < D; d++) {
      for (int q = 0; q < 26; q++) {
        if (ts[d] == q) {
          continue;
        }

        int next_score = calc_diff(d, q);

        if (score < next_score) {
          ts[d] = q;
          score = next_score;
        }
      }
    }
  }

  for (auto &&t : ts) {
    cout << t + 1 << endl;
  }

  return 0;
}
Problem p02618 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  auto start = steady_clock::now();

  int D;
  vector<int> cs(26);
  cin >> D;
  for (auto &&c : cs) {
    cin >> c;
  }
  vector<vector<int>> sss(D, vector<int>(26));
  for (auto &&ss : sss) {
    for (auto &&s : ss) {
      cin >> s;
    }
  }

  vector<int> ts(D, 0);

  auto calc_score = [&] {
    vector<int> last(26, -1);

    int s = 0;

    for (int d = 0; d < D; d++) {
      s += sss[d][ts[d]];

      last[ts[d]] = d;

      for (int i = 0; i < 26; i++) {
        s -= cs[i] * (d - last[i]);
      }
    }

    // return max(0, 1000000 + s);
    return s;
  };

  auto calc_diff = [&](int d, int q) {
    int p = ts[d];

    ts[d] = q;

    int ret = calc_score();

    ts[d] = p;

    return ret;
  };

  int score = calc_score();

  while (duration_cast<milliseconds>(steady_clock::now() - start).count() <
         1950) {
    for (int d = 0; d < D; d++) {
      for (int q = 0; q < 26; q++) {
        if (ts[d] == q) {
          continue;
        }

        int next_score = calc_diff(d, q);

        if (score < next_score) {
          ts[d] = q;
          score = next_score;
        }
      }
    }
  }

  for (auto &&t : ts) {
    cout << t + 1 << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  auto start = steady_clock::now();

  int D;
  vector<int> cs(26);
  cin >> D;
  for (auto &&c : cs) {
    cin >> c;
  }
  vector<vector<int>> sss(D, vector<int>(26));
  for (auto &&ss : sss) {
    for (auto &&s : ss) {
      cin >> s;
    }
  }

  vector<int> ts(D, 0);

  auto calc_score = [&] {
    vector<int> last(26, -1);

    int s = 0;

    for (int d = 0; d < D; d++) {
      s += sss[d][ts[d]];

      last[ts[d]] = d;

      for (int i = 0; i < 26; i++) {
        s -= cs[i] * (d - last[i]);
      }
    }

    return max(0, 1000000 + s);
  };

  auto calc_diff = [&](int d, int q) {
    int p = ts[d];

    ts[d] = q;

    int ret = calc_score();

    ts[d] = p;

    return ret;
  };

  int score = calc_score();

  while (duration_cast<milliseconds>(steady_clock::now() - start).count() <
         1990) {
    for (int d = 0; d < D; d++) {
      for (int q = 0; q < 26; q++) {
        if (ts[d] == q) {
          continue;
        }

        int next_score = calc_diff(d, q);

        if (score < next_score) {
          ts[d] = q;
          score = next_score;
        }
      }
    }
  }

  for (auto &&t : ts) {
    cout << t + 1 << endl;
  }

  return 0;
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int d;
  cin >> d;
  const int ContestCount = 26;
  vector<int> c(ContestCount);
  rep(i, ContestCount) cin >> c.at(i);
  vector<vector<int>> s(d, vector<int>(ContestCount));
  rep(i, d) {
    rep(j, ContestCount) { cin >> s.at(i).at(j); }
  }
  vector<int> res(d);
  rep(i, d) { res.at(i) = 1; }
  rep(i, d) { cout << res.at(i) << endl; }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int d;
  cin >> d;
  const int ContestCount = 26;
  vector<int> c(ContestCount);
  rep(i, ContestCount) cin >> c.at(i);
  vector<vector<int>> s(d, vector<int>(ContestCount));
  rep(i, d) {
    rep(j, ContestCount) { cin >> s.at(i).at(j); }
  }
  vector<int> res(ContestCount);
  rep(i, d) { res.at(i) = i; }
  rep(i, d) { cout << res.at(i) << endl; }
  return 0;
}
Problem p02618 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;

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

int scoring(const vector<int> &t) {
  int v = 0;
  vector<int> last(26, -1);
  rep(i, D) {
    v += s[i][t[i]];
    last[t[i]] = i;
    rep(j, 26) { v -= c[j] * (i - last[j]); }
  }
  return v;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  auto start = chrono::system_clock::now();

  cin >> D;
  rep(i, 26) cin >> c[i];
  s.resize(D, vector<int>(26));
  rep(i, D) rep(j, 26) cin >> s[i][j];

  vector<int> t(D);

  rep(i, D) t[i] = max_element(s[i].begin(), s[i].end()) - s[i].begin();

  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> rand_d(0, D - 1);
  uniform_int_distribution<> rand_t(0, 25);

  int v = scoring(t);
  int x = 0;
  while (true) {
    int to_d = rand_d(mt);
    int to_t = rand_t(mt);
    if (t[to_d] == to_t)
      continue;
    int old = t[to_d];
    t[to_d] = to_t;
    int nv = scoring(t);
    if (nv < v)
      t[to_d] = old;
    if (x % 1000 == 0) {
      auto end = chrono::system_clock::now();
      auto dur = end - start;
      auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
      if (msec >= 1970)
        break;
    }
    x++;
  }
  rep(i, D) cout << t[i] + 1 << '\\n';
}


Error: TLE

Fixed submission:

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;

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

int scoring(const vector<int> &t) {
  int v = 0;
  vector<int> last(26, -1);
  rep(i, D) {
    v += s[i][t[i]];
    last[t[i]] = i;
    rep(j, 26) { v -= c[j] * (i - last[j]); }
  }
  return v;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  auto start = chrono::system_clock::now();

  cin >> D;
  rep(i, 26) cin >> c[i];
  s.resize(D, vector<int>(26));
  rep(i, D) rep(j, 26) cin >> s[i][j];

  vector<int> t(D);

  rep(i, D) t[i] = max_element(s[i].begin(), s[i].end()) - s[i].begin();

  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> rand_d(0, D - 1);
  uniform_int_distribution<> rand_t(0, 25);

  int v = scoring(t);
  int x = 0;
  while (true) {
    int to_d = rand_d(mt);
    int to_t = rand_t(mt);
    if (t[to_d] == to_t)
      continue;
    int old = t[to_d];
    t[to_d] = to_t;
    int nv = scoring(t);
    if (nv < v)
      t[to_d] = old;
    if (x % 10000 == 0) {
      auto end = chrono::system_clock::now();
      auto dur = end - start;
      auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
      if (msec >= 1970)
        break;
    }
    x++;
  }
  rep(i, D) cout << t[i] + 1 << '\\n';
}
Problem p02618 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int D;
vector<int> c(30, 0);
vector<vector<int>> s(400, vector<int>(30, 0));

struct schedule {
  int score = 0;
  vector<int> contest;
  vector<int> last;

  schedule() { last.assign(30, 0); };

  bool operator<(const schedule &s) const { return score > s.score; }
};

void input() {
  cin >> D;
  for (int i = 1; i <= 26; ++i) {
    cin >> c[i];
  }
  for (int i = 1; i <= D; ++i) {
    for (int j = 1; j <= 26; ++j) {
      cin >> s[i][j];
    }
  }
}

schedule calc_score(schedule sc, int con) {
  schedule ret = sc;
  int day = sc.contest.size() + 1;
  ret.last[con] = day;
  ret.contest.push_back(con);
  ret.score += s[day][con];
  for (int i = 1; i <= 26; ++i) {
    ret.score -= c[i] * (day - ret.last[i]);
  }

  return ret;
}

int main() {
  constexpr int BEAM = 77;
  input();

  vector<schedule> curr;
  curr.emplace_back(schedule());
  for (int d = 1; d <= D; ++d) {
    vector<schedule> nxt;
    for (auto sc : curr) {
      for (int i = 1; i <= 26; ++i) {
        nxt.push_back(calc_score(sc, i));
      }
    }
    sort(nxt.begin(), nxt.end());
    if (nxt.size() > BEAM) {
      nxt.resize(BEAM);
    }
    curr = nxt;
  }
  // cerr << "score = " << curr[0].score << endl;
  for (auto t : curr[0].contest) {
    cout << t << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int D;
vector<int> c(30, 0);
vector<vector<int>> s(400, vector<int>(30, 0));

struct schedule {
  int score = 0;
  vector<int> contest;
  vector<int> last;

  schedule() { last.assign(30, 0); };

  bool operator<(const schedule &s) const { return score > s.score; }
};

void input() {
  cin >> D;
  for (int i = 1; i <= 26; ++i) {
    cin >> c[i];
  }
  for (int i = 1; i <= D; ++i) {
    for (int j = 1; j <= 26; ++j) {
      cin >> s[i][j];
    }
  }
}

schedule calc_score(schedule sc, int con) {
  schedule ret = sc;
  int day = sc.contest.size() + 1;
  ret.last[con] = day;
  ret.contest.push_back(con);
  ret.score += s[day][con];
  for (int i = 1; i <= 26; ++i) {
    ret.score -= c[i] * (day - ret.last[i]);
  }

  return ret;
}

int main() {
  constexpr int BEAM = 2500;
  input();

  vector<schedule> curr;
  curr.emplace_back(schedule());
  for (int d = 1; d <= D; ++d) {
    vector<schedule> nxt;
    for (auto sc : curr) {
      for (int i = 1; i <= 26; ++i) {
        nxt.push_back(calc_score(sc, i));
      }
    }
    sort(nxt.begin(), nxt.end());
    if (nxt.size() > BEAM) {
      nxt.resize(BEAM);
    }
    curr = nxt;
  }
  // cerr << "score = " << curr[0].score << endl;
  for (auto t : curr[0].contest) {
    cout << t << endl;
  }

  return 0;
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <iostream>  // cout, endl, cin
#include <math.h>    // sqrt
#include <string>    // string, to_string, stoi
#include <vector>    // vector
using namespace std;
typedef long long ll;

int main() {
  ll D;
  cin >> D;
  vector<ll> c(26);
  for (int i = 0; i < 26; i++) {
    cin >> c.at(i);
  }
  vector<vector<ll>> s(D, vector<ll>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s.at(i).at(j);
    }
  }
  vector<ll> v(26, 0);
  vector<ll> last;
  for (ll i = 0; i < D; i++) {
    ll pointd = 0;
    int vd = 0;
    for (int j = 0; j < 26; j++) {
      last = v;
      last.at(j) = i + 1;
      ll sumd = 0;
      for (int k = 0; k < 26; k++) {
        if (k == j) {
          sumd += s.at(i).at(k);
        } else {
          sumd -= (i - last.at(k) + 1) * c.at(k);
        }
      }
      if (pointd < sumd) {
        vd = j + 1;
      }
      if (j == 0) {
        pointd = sumd;
        vd = 1;
      } else {
        pointd = max(pointd, sumd);
      }
    }
    v.at(vd - 1) = i + 1;
    cout << vd << endl;
  }
}


Error: WA

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <iostream>  // cout, endl, cin
#include <math.h>    // sqrt
#include <string>    // string, to_string, stoi
#include <vector>    // vector
using namespace std;
typedef long long ll;

int main() {
  ll D;
  cin >> D;
  vector<ll> c(26);
  for (int i = 0; i < 26; i++) {
    cin >> c.at(i);
  }
  vector<vector<ll>> s(D, vector<ll>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s.at(i).at(j);
    }
  }
  vector<ll> v(26, 0);
  vector<ll> last;
  for (ll i = 0; i < D; i++) {
    ll pointd = 0;
    int vd = 0;
    for (int j = 0; j < 26; j++) {
      last = v;
      last.at(j) = i + 1;
      ll sumd = 0;
      for (int k = 0; k < 26; k++) {
        if (k == j) {
          sumd += s.at(i).at(k);
        } else {
          sumd -= (i - last.at(k) + 1) * c.at(k);
        }
      }
      if (pointd < sumd) {
        vd = j + 1;
      }
      pointd = max(pointd, sumd);
    }
    v.at(vd - 1) = i + 1;
    cout << vd << endl;
  }
}