alexjercan/bugnet huggingface dataset:
Problem p02618 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, -1, sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;
const int MAX_N = 2e5;

int d, c[365], s[365][26], t[365], last[26], u;

void input() {
  cin >> d;
  rep(i, 26) cin >> c[i];
  rep(i, d) {
    rep(j, 26) { cin >> s[i][j]; }
  }
  rep(i, d) {
    int k;
    cin >> k;
    k--;
    t[i] = k;
  }
  fill(last, last + 26, 0);
}

int test(int k, int i) {
  ll res = 0;
  rep(j, 26) {
    if (j == k)
      continue;
    res -= c[j] * last[j];
  }

  return res + s[i][k];
}

void greedy() {
  rep(i, d) {
    rep(i, 26) last[i]++;
    int res = -INF;
    rep(k, 26) {
      if (res < test(k, i)) {
        u = k;
        res = test(k, i);
      }
    }
    last[u] = 0;
    t[i] = u;
  }
}

int p_calc() {
  ll res = 0;
  int last[26];
  fill(last, last + 26, 0);
  rep(i, d) {
    res += s[i][t[i]];
    rep(i, 26) last[i]++;
    last[t[i]] = 0;
    rep(j, 26) { res -= c[j] * last[j]; }
  }

  return res;
}

int main() {
  input();
  greedy();
  ll ans = p_calc();

  rep(i, 10000) {
    int p = i % 365, q, tmp = t[p];

    q = s[i % 365][i % 26] % 26;

    t[p] = q;
    if (ans > p_calc()) {
      t[p] = tmp;
    }
  }

  rep(i, d) cout << t[i] + 1 << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, -1, sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;
const int MAX_N = 2e5;

int d, c[365], s[365][26], t[365], last[26], u;

void input() {
  cin >> d;
  rep(i, 26) cin >> c[i];
  rep(i, d) {
    rep(j, 26) { cin >> s[i][j]; }
  }
  rep(i, d) {
    int k;
    cin >> k;
    k--;
    t[i] = k;
  }
  fill(last, last + 26, 0);
}

int test(int k, int i) {
  ll res = 0;
  rep(j, 26) {
    if (j == k)
      continue;
    res -= c[j] * last[j];
  }

  return res + s[i][k];
}

void greedy() {
  rep(i, d) {
    rep(i, 26) last[i]++;
    int res = -INF;
    rep(k, 26) {
      if (res < test(k, i)) {
        u = k;
        res = test(k, i);
      }
    }
    last[u] = 0;
    t[i] = u;
  }
}

int p_calc() {
  ll res = 0;
  int last[26];
  fill(last, last + 26, 0);
  rep(i, d) {
    res += s[i][t[i]];
    rep(i, 26) last[i]++;
    last[t[i]] = 0;
    rep(j, 26) { res -= c[j] * last[j]; }
  }

  return res;
}

int main() {
  input();
  greedy();
  ll ans = p_calc();

  rep(i, 1000000) {
    int p = i % 365, q, tmp = t[p];

    q = s[i % 365][i % 26] % 26;

    t[p] = q;
    if (ans > p_calc()) {
      t[p] = tmp;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

const int w = 13;
const int k = 300;
const int n = 26;
int d;

VI c(n);
VVI s(365, VI(n));

struct st {
  VI a;
  ll score;
  bool operator<(const st &another) const { return score < another.score; };
};

vector<st> f(st p) {
  VI a = p.a;
  ll score = p.score;
  int now = a.size() + 1;
  VI last(n, 0);
  REP(i, a.size())
  last[a[i]] = i + 1;
  VI down(n);
  ll downsum = 0;
  REP(i, n) {
    down[i] = c[i] * (now - last[i]);
    downsum += down[i];
  }
  a.push_back(-1);
  vector<st> tmp;
  REP(i, n) {
    a[now - 1] = i;
    tmp.push_back({a, score - downsum + down[i] + s[now - 1][i]});
  }
  sort(ALL(tmp));
  vector<st> ret;
  REP(i, w)
  ret.push_back(tmp[n - 1 - i]);
  return ret;
}

int main() {
  cin >> d;
  REP(i, n) cin >> c[i];
  REP(i, d) REP(j, n) cin >> s[i][j];
  priority_queue<st> q;
  VI a(0);
  q.push({a, 0});
  REP(i, d) {
    priority_queue<st> next;
    REP(j, k) {
      if (q.empty())
        break;
      for (auto nx : f(q.top()))
        next.push(nx);
      q.pop();
    }
    q = next;
  }
  REP(i, d)
  cout << q.top().a[i] + 1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

const int w = 18;
const int k = 350;
const int n = 26;
int d;

VI c(n);
VVI s(365, VI(n));

struct st {
  VI a;
  ll score;
  bool operator<(const st &another) const { return score < another.score; };
};

vector<st> f(st p) {
  VI a = p.a;
  ll score = p.score;
  int now = a.size() + 1;
  VI last(n, 0);
  REP(i, a.size())
  last[a[i]] = i + 1;
  VI down(n);
  ll downsum = 0;
  REP(i, n) {
    down[i] = c[i] * (now - last[i]);
    downsum += down[i];
  }
  a.push_back(-1);
  vector<st> tmp;
  REP(i, n) {
    a[now - 1] = i;
    tmp.push_back({a, score - downsum + down[i] + s[now - 1][i]});
  }
  sort(ALL(tmp));
  vector<st> ret;
  REP(i, w)
  ret.push_back(tmp[n - 1 - i]);
  return ret;
}

int main() {
  cin >> d;
  REP(i, n) cin >> c[i];
  REP(i, d) REP(j, n) cin >> s[i][j];
  priority_queue<st> q;
  VI a(0);
  q.push({a, 0});
  REP(i, d) {
    priority_queue<st> next;
    REP(j, k) {
      if (q.empty())
        break;
      for (auto nx : f(q.top()))
        next.push(nx);
      q.pop();
    }
    q = next;
  }
  REP(i, d)
  cout << q.top().a[i] + 1 << endl;
  return 0;
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

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

struct status {
  vector<int> ans;
  vector<long long> last;
};

bool operator<(pair<long long, status> l, pair<long long, status> r) {
  if (l.first != r.first)
    return l.first < r.first;
  return l.first < r.first;
}

int main() {
  int d;
  cin >> d;
  vector<long long> c(26);
  for (int i = 0; i < 26; i++)
    cin >> c.at(i);
  vector<vector<long long>> s(d, vector<long long>(26));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++)
      cin >> s.at(i).at(j);
  }

  priority_queue<pair<long long, status>> beam;
  vector<int> an(0);
  vector<long long> la(26, 0);
  status sta = {an, la};
  beam.push({(long long)0, sta});
  for (int day = 0; day < d; day++) {
    priority_queue<pair<long long, status>> now;

    while (beam.size() > 0) {
      long long score = beam.top().first;
      auto state = beam.top().second;
      beam.pop();
      state.ans.push_back(0);

      for (int i = 0; i < 26; i++) {
        long long sum = score;
        auto n = state;
        n.last.at(i) = day;
        n.ans.at(day) = i + 1;

        sum += s.at(day).at(i);
        for (int j = 0; j < 26; j++) {
          sum -= c.at(j) * (day - n.last.at(j));
        }

        now.push({sum, n});
      }
    }
    for (int i = 0; i < 10; i++) {
      if (now.size() <= 0)
        break;
      beam.push(now.top());
      now.pop();
    }
  }

  auto res = beam.top().second.ans;
  for (auto now : res)
    cout << now << endl;
}


Error: WA

Fixed submission:

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

struct status {
  vector<int> ans;
  vector<long long> last;
};

bool operator<(pair<long long, status> l, pair<long long, status> r) {
  if (l.first != r.first)
    return l.first < r.first;
  else
    l.second.ans < r.second.ans;
}

int main() {
  int d;
  cin >> d;
  vector<long long> c(26);
  for (int i = 0; i < 26; i++)
    cin >> c.at(i);
  vector<vector<long long>> s(d, vector<long long>(26));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++)
      cin >> s.at(i).at(j);
  }

  priority_queue<pair<long long, status>> beam;
  vector<int> an(0);
  vector<long long> la(26, 0);
  status sta = {an, la};
  beam.push({(long long)0, sta});
  for (int day = 0; day < d; day++) {
    priority_queue<pair<long long, status>> now, cle;
    for (int i = 0; i < 5; i++) {
      if (beam.size() <= 0)
        break;
      now.push(beam.top());
      beam.pop();
    }

    while (now.size() > 0) {
      long long score = now.top().first;
      auto state = now.top().second;
      now.pop();
      state.ans.push_back(0);

      for (int i = 0; i < 26; i++) {
        long long sum = score;
        auto n = state;
        n.last.at(i) = day;
        n.ans.at(day) = i + 1;

        sum += s.at(day).at(i);
        for (int j = 0; j < 26; j++) {
          sum -= c.at(j) * (day - n.last.at(j));
        }

        beam.push({sum, n});
      }
    }
  }

  auto res = beam.top().second.ans;
  for (auto now : res)
    cout << now << endl;
}
Problem p02618 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#include <random>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int D;

int c[27];
int s[366][27];
int last[27];

vector<int> ans;
ll ans_score;

ll calcScore() {
  rep(i, 27) last[i] = 0;
  ll score = 0;
  for (int d = 1; d <= D; ++d) {
    int t = ans[d];
    score += s[d][t];
    last[t] = d;
    for (int i = 1; i <= 26; ++i) {
      score -= c[i] * (d - last[i]);
    }
  }
  return score;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  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];
    }
  }
  ans.resize(D, 1);
  ans_score = calcScore();
  // local search
  std::random_device rnd;
  std::mt19937 mt(rnd());
  std::uniform_int_distribution<> randD(1, D);
  rep(_, 10000) {
    int d = randD(mt);
    for (int q = 1; q <= 26; ++q) {
      int old = ans[d];
      ans[d] = q;
      ll score = calcScore();
      if (ans_score > score)
        ans[d] = old;
      else
        ans_score = score;
    }
  }
  rep(i, D) cout << ans[i] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <random>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int D;

ll c[27];
ll s[366][27];
ll last[27];

vector<int> ans;
ll ans_score;

ll calcScore() {
  rep(i, 27) last[i] = 0;
  ll score = 0;
  for (ll d = 1; d <= D; ++d) {
    int t = ans[d];
    score += s[d][t];
    last[t] = d;
    for (int i = 1; i <= 26; ++i) {
      score -= c[i] * (d - last[i]);
    }
  }
  return score;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  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];
    }
  }
  ans.resize(D, 1);
  ans_score = calcScore();
  // local search
  std::random_device rnd;
  std::mt19937 mt(rnd());
  std::uniform_int_distribution<> randD(1, D);
  rep(_, 20000) {
    int d = randD(mt);
    for (int q = 1; q <= 26; ++q) {
      ll old = ans[d];
      ans[d] = q;
      ll score = calcScore();
      if (ans_score > score)
        ans[d] = old;
      else
        ans_score = score;
    }
  }
  rep(i, D) cout << ans[i] << endl;
  return 0;
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);

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

  int D;
  cin >> D;
  int c[26];
  int s[D][26];
  int t[D];
  int ok[26];
  rep(i, 26) ok[i] = -1;
  rep(i, 26) cin >> c[i];
  rep(i, D) {
    rep(j, 26) { cin >> s[i][j]; }
  }
  /*
  rep(i,D){
          cin >> t[i];
          --t[i];
  }
  */
  int cnt = 0;
  int num;
  rep(i, D) {
    int maxi = -INF;
    rep(k, 26) {
      int ans = 0;
      ans += s[i][k];
      // ok[t[i]] = i;
      rep(j, 26) {
        if (j == k)
          continue;
        ans -= c[j] * (i - ok[j]);
      }
      if (maxi < ans) {
        maxi = ans;
        num = k;
      }
    }
    cout << num + 1 << endl;
    ok[num] = i;
    t[i] = num;
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);

set<int> st[26];

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

  int D;
  cin >> D;
  rep(i, 26) {
    st[i].insert(-1);
    st[i].insert(D);
  }
  int c[26];
  int s[D][26];
  int t[D];
  int ok[26];
  rep(i, 26) ok[i] = -1;
  rep(i, 26) cin >> c[i];
  rep(i, D) {
    rep(j, 26) { cin >> s[i][j]; }
  }
  rep(i, D) {
    cin >> t[i];
    --t[i];
    st[t[i]].insert(i);
  }
  int ans = 0;
  rep(i, D) {
    ans += s[i][t[i]];
    ok[t[i]] = i;
    rep(j, 26) { ans -= c[j] * (i - ok[j]); }
    // cout << ans << endl;
  }
  int M;
  cin >> M;
  int d[M], q[M];
  rep(i, M) {
    cin >> d[i] >> q[i];
    --d[i];
    --q[i];
  }
  rep(i, M) {
    int _ = t[d[i]]; // コンテストの種類
    t[d[i]] = q[i];
    st[_].erase(d[i]);
    auto itr = st[_].upper_bound(d[i]);
    int W2 = *itr;
    --itr;
    int W1 = *itr;
    ans -= c[_] * abs(d[i] - W1) * abs(W2 - d[i]);
    auto itr1 = st[q[i]].upper_bound(d[i]);
    int A2 = *itr1;
    --itr1;
    int A1 = *itr1;
    ans += c[q[i]] * abs(d[i] - A1) * abs(A2 - d[i]);
    st[q[i]].insert(d[i]);
    ans += s[d[i]][q[i]] - s[d[i]][_];
    cout << ans << endl;
  }
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

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

signed main() {

  int d;
  vector<int> c(26);
  cin >> d;
  for (auto &ci : c)
    cin >> ci;
  vector<vector<int>> s(d, vector<int>(26));
  for (auto &si : s)
    for (auto &sij : si)
      cin >> sij;

  vector<int> last(26, 0);

  auto calc_satisfaction_level = [&](int d, int i) {
    int res = s[d][i];
    for (int j = 0; j < 26; ++j) {
      if (i == j)
        continue;
      res -= c[j] * (d - last[j] + 1);
    }
    return res;
  };

  vector<int> ans(d);

  //-----------------------------------------------------

  auto test_all_get_max = [&](int di) -> pair<int, int> {
    // 日付を引数にして全てのコンテストタイプを試してmaxscoreになるタイプを返す
    // 上位k個を返す
    int k = 5;
    int val_max = -(1 << 28), type_max = -1;
    vector<pair<int, int>> valtype_max(26);
    auto chmax = [](auto &a, auto b) {
      if (a < b) {
        a = b;
        return true;
      }
      return false;
    };
    for (int type = 0; type < 26; ++type) {
      if (chmax(val_max, calc_satisfaction_level(di, type)))
        type_max = type;
    }
    return {val_max, type_max};
  };

  for (int di = 0; di < d; ++di) {
    auto [vi, type] = test_all_get_max(di);
    if (type == -1)
      type = 0;
    ans[di] = type;
    last[type] = di + 1;
  }

  //-----------------------------------------------------

  for (auto x : ans) {
    assert(1 <= x + 1 && x + 1 <= 26);
    cout << x + 1 << endl;
  }
}

Error: WA

Fixed submission:

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

signed main() {

  int d;
  vector<int> c(26);
  cin >> d;
  for (auto &ci : c)
    cin >> ci;
  vector<vector<int>> s(d, vector<int>(26));
  for (auto &si : s)
    for (auto &sij : si)
      cin >> sij;

  vector<int> last(26, 0);

  auto calc_satisfaction_level = [&](int d, int i) {
    int res = s[d][i];
    for (int j = 0; j < 26; ++j) {
      if (i == j)
        continue;
      res -= c[j] * (d - last[j] + 1);
    }
    return res;
  };

  vector<int> ans(d);

  //-----------------------------------------------------

  auto test_all_get_max = [&](int di) -> pair<int, int> {
    // 日付を引数にして全てのコンテストタイプを試してmaxscoreになるタイプを返す
    // 上位k個を返す
    int k = 5;
    int val_max = -1, type_max = -1;
    vector<pair<int, int>> valtype_max(26);
    auto chmax = [](auto &a, auto b) {
      if (a < b) {
        a = b;
        return true;
      }
      return false;
    };
    for (int type = 0; type < 26; ++type) {
      if (chmax(val_max, calc_satisfaction_level(di, type)))
        type_max = type;
    }
    return {val_max, type_max};
  };

  for (int di = 0; di < d; ++di) {
    auto [vi, type] = test_all_get_max(di);
    ans[di] = type;
    last[type] = di + 1;
  }

  //-----------------------------------------------------

  for (auto x : ans) {
    assert(1 <= x + 1 && x + 1 <= 26);
    cout << x + 1 << endl;
  }
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

/*
 *  Lang    : C++
 *  Author  : little_angel
 */

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define dbg(x) cerr << "[" << #x << " = " << x << "]"

int D;
vector<vector<int>> s;
vector<int> c;

int get_score(vector<int> &sc) {
  unordered_map<int, int> last;
  int S = 0;
  for (int i = 0; i < D; ++i) {
    S += s[i][sc[i] - 1];
    last[sc[i] - 1] = i + 1;
    for (int j = 0; j < 26; j++)
      S -= c[j] * (i + 1 - last[j]);
    //        dbg(S) << endl;
  }
  return max(1000000 + S, 0ll);
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  //    freopen("in.txt", "r", stdin);
  //    freopen("out.txt", "w", stdout);

  cin >> D;
  c = vector<int>(26);
  s = vector<vector<int>>(D, vector<int>(26));
  for (auto &i : c)
    cin >> i;
  for (auto &i : s) {
    for (auto &j : i)
      cin >> j;
  }

  vector<int> ans(D);
  for (auto &i : ans)
    cin >> i;
  unordered_map<int, int> last;
  int tm = 1 + rand() % 26;
  int S = s[0][tm - 1];
  ans[0] = tm;
  last[tm] = 1;

  for (int i = 1; i < D; ++i) {
    int cur = -1e18, pos = -1;
    for (int j = 0; j < 26; ++j) {
      int sc = S + s[i][j];

      for (int k = 0; k < 26; ++k) {
        if (k == j)
          continue;
        sc -= c[k] * (i + 1 - last[k]);
      }

      if (sc > cur) {
        cur = sc;
        pos = j;
      }
    }
    ans[i] = pos + 1;
    last[pos] = i + 1;
  }
  for (auto i : ans)
    cout << i << endl;

  //    int score = get_score(ans);
  //    dbg(score) << endl;
}

Error: -11

Fixed submission:

/*
 *  Lang    : C++
 *  Author  : little_angel
 */

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define dbg(x) cerr << "[" << #x << " = " << x << "]"

int D;
vector<vector<int>> s;
vector<int> c;

int get_score(vector<int> &sc) {
  unordered_map<int, int> last;
  int S = 0;
  for (int i = 0; i < D; ++i) {
    S += s[i][sc[i] - 1];
    last[sc[i] - 1] = i + 1;
    for (int j = 0; j < 26; j++)
      S -= c[j] * (i + 1 - last[j]);
    //        dbg(S) << endl;
  }
  return max(1000000 + S, 0ll);
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);

  cin >> D;
  c = vector<int>(26);
  s = vector<vector<int>>(D, vector<int>(26));
  for (auto &i : c)
    cin >> i;
  for (auto &i : s) {
    for (auto &j : i)
      cin >> j;
  }

  vector<int> ans(D);
  unordered_map<int, int> last;
  int tm = 1 + rand() % 26;
  int S = s[0][tm - 1];
  ans[0] = tm;
  last[tm] = 1;

  for (int i = 1; i < D; ++i) {
    int cur = -1e18, pos = -1;
    for (int j = 0; j < 26; ++j) {
      int sc = S + s[i][j];

      for (int k = 0; k < 26; ++k) {
        if (k == j)
          continue;
        sc -= c[k] * (i + 1 - last[k]);
      }

      if (sc > cur) {
        cur = sc;
        pos = j;
      }
    }
    ans[i] = pos + 1;
    last[pos] = i + 1;
  }
  for (auto i : ans)
    cout << i << endl;

  int score = get_score(ans);
  dbg(score) << endl;
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\\n';
#define OUT(n) cout << (n) << '\\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main(void) {
  IOS const int A = 26;
  int D;
  cin >> D;
  vector<int> c(D);
  REP(i, A) cin >> c[i];
  vector<vector<int>> s(D, vector<int>(A));
  REP(i, D) REP(j, A) cin >> s[i][j];

  vector<int> last(A, -1);
  REP(i, D) {
    int mx = 0, a = -1;
    REP(j, A) {
      int tmp = (i - last[j]) * c[j] + s[i][j];
      if (mx < tmp) {
        mx = tmp;
        a = j;
      }
    }
    OUT(a + 1)
    last[a] = i;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\\n';
#define OUT(n) cout << (n) << '\\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main(void) {
  IOS const int A = 26;
  int D;
  cin >> D;
  vector<int> c(D);
  REP(i, D) cin >> c[i];
  vector<vector<int>> s(D, vector<int>(A));
  REP(i, D) REP(j, A) cin >> s[i][j];

  vector<int> last(A, -1);
  REP(i, D) {
    int mx = 0, a = -1;
    REP(j, D) {
      int tmp = last[j] * c[j] + s[i][j];
      if (mx < tmp) {
        mx = tmp;
        a = j;
      }
    }
    OUT(a + 1)
    last[a] = i;
  }

  return 0;
}