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

//
// Created by seriru on 2020/06/28.
//

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

constexpr int D = 365;
constexpr int NUM = 26;
int score = 0;

void print(vector<int> const &ans) {
  for (int i = 0; i < D; ++i) {
    cout << ans[i] << endl;
  }
}

int main() {
  int _;
  cin >> _;
  vector<int> C(NUM);
  vector<vector<int>> S(D, vector<int>(NUM));
  vector<int> ans(D + 1);
  vector<vector<int>> last(D + 1, vector<int>(NUM));

  for (int i = 0; i < NUM; ++i) {
    cin >> C[i];
  }

  for (int i = 0; i < D; ++i) {
    int maxScore = 0;
    int contest = 0;
    for (int j = 0; j < NUM; ++j) {
      cin >> S[i][j];
      if (maxScore < S[i][j]) {
        maxScore = S[i][j];
        contest = j + 1;
      }
    }

    ans[i] = contest;
  }

  // greedy(ans, last, C);
  // calcBaseScore(ans, S, last, C);
  print(ans);
}


Error: WA

Fixed submission:

//
// Created by seriru on 2020/06/28.
//

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

constexpr int D = 365;
constexpr int NUM = 26;
int score = 0;

void print(vector<int> const &ans) {
  int cnt = 0;
  for (int i = 0; i < D; ++i) {
    cout << ans[i] << endl;
  }
}

constexpr int PEN_OVER = 1000;

auto loss(vector<int> const &ans, vector<int> const &C, int &total) {
  array<int, NUM> last;
  vector<pair<int, int>> p;
  int loss = 0;
  for (int day = 0; day < D; ++day) {
    int contest = ans[day];
    last[contest] = day + 1;
    for (int i = 0; i < NUM; ++i) {
      int pen = (day + 1 - last[i]) * C[i];
      loss += pen;
      if (pen > PEN_OVER) {
        p.push_back({i, day});
      }
    }
  }
  total = loss;
  return p;
}

// xorshift128(2^128-1周期の疑似乱数)
struct XorShift {
  using U32 = uint32_t;
  U32 x;
  U32 y;
  U32 z;
  U32 w;

  // XorShiftでは初期値は0以外ならなんでもいい。
  XorShift() : x(123456789), y(362436069), z(521288629), w(88675123) {}

  // 次の疑似乱数
  U32 next() {
    U32 t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
  }

  U32 nextInt(int range) { return next() % range; }
};

int main() {
  int _;
  cin >> _;
  vector<int> C(NUM);
  vector<vector<int>> S(D, vector<int>(NUM));
  vector<int> ans(D + 1);

  for (int i = 0; i < NUM; ++i) {
    cin >> C[i];
  }

  for (int i = 0; i < D; ++i) {
    int maxScore = 0;
    int contest = 0;
    for (int j = 0; j < NUM; ++j) {
      cin >> S[i][j];
      if (maxScore < S[i][j]) {
        maxScore = S[i][j];
        contest = j + 1;
      }
    }

    ans[i] = contest;
    score += maxScore;
  }

  print(ans);

  XorShift rand;

  int cnt = 1000;
  int los;
  auto change = loss(ans, C, los);
  score -= los;
  auto cpy = ans;
  while (--cnt) {
    int idx = rand.nextInt(change.size());
    auto pa = change[idx];

    cpy[pa.second] = pa.first;
    int tmp = 0;
    for (int i = 0; i < D; ++i) {
      tmp += S[i][cpy[i]];
    }
    auto ch = loss(cpy, C, los);
    if (tmp - los >= score) {
      score = tmp - los;
      ans = cpy;
      change = ch;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
int D, c[27], s[366][27];

int sco(vector<int> &t, int k, int x) {
  int S = 0, L[27] = {};
  REP(i, D) {
    if (i == k) {
      S += s[i][x];
      L[x] = i;
    } else {
      S += s[i][t[i]];
      L[t[i]] = i;
    }
    REP(j, 27) { S -= c[j] * (i - L[j]); }
  }
  return S;
}

int saga(int d, vector<int> &L) {
  int S = 0;
  REP(i, 27) { S += c[i] * (d - L[i]); }
  return S;
}

int main() {
  cin >> D;
  D++;
  REP(i, 27) { cin >> c[i]; }
  REP(i, D) {
    REP(j, 27) { cin >> s[i][j]; }
  }
  vector<int> t(D), last(27, 0);

  REP(i, D) {
    int a = 1, S = -1000000, u = 0, m = 0;
    REP(j, 27) {
      u = s[i][j];
      u -= saga(i, last);
      u += c[j] * (i - last[j]);
      if (S < u) {
        a = j;
        S = u;
      }
    }
    t[i] = a;
    last[a] = i;
  }
  int S = sco(t, 0, 0), T = 0, n = 0;
  REP(i, D) {
    REP(j, 27) {
      T = sco(t, i, j);
      if (S < T) {
        t[i] = j;
        S = T;
        if (n <= 100) {
          i = 1;
          n++;
          break;
        }
      }
    }
  }

  REP(i, D) { cout << t[i] << "\\n"; }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
int D, c[27], s[366][27];

int sco(vector<int> &t, int k, int x) {
  int S = 0, L[27] = {};
  REP(i, D) {
    if (i == k) {
      S += s[i][x];
      L[x] = i;
    } else {
      S += s[i][t[i]];
      L[t[i]] = i;
    }
    REP(j, 27) { S -= c[j] * (i - L[j]); }
  }
  return S;
}

int saga(int d, vector<int> &L) {
  int S = 0;
  REP(i, 27) { S += c[i] * (d - L[i]); }
  return S;
}

int main() {
  cin >> D;
  D++;
  REP(i, 27) { cin >> c[i]; }
  REP(i, D) {
    REP(j, 27) { cin >> s[i][j]; }
  }
  vector<int> t(D), last(27, 0);

  REP(i, D) {
    int a = 1, S = -1000000, u = 0, m = 0;
    REP(j, 27) {
      u = s[i][j];
      u -= saga(i, last);
      u += c[j] * (i - last[j]);
      if (S < u) {
        a = j;
        S = u;
      }
    }
    t[i] = a;
    last[a] = i;
  }
  int S = sco(t, 0, 0), T = 0, n = 0;
  REP(i, D) {
    REP(j, 27) {
      T = sco(t, i, j);
      if (S < T) {
        t[i] = j;
        S = T;
        if (n <= 10000) {
          i = 1;
          n++;
          break;
        }
      }
    }
  }

  REP(i, D) { cout << t[i] << "\\n"; }
}
Problem p02618 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
int D, c[27], s[366][27];

int sco(vector<int> &t, int k, int x) {
  int S = 0, L[27] = {};
  REP(i, D) {
    if (i == k) {
      S += s[i][x];
      L[x] = i;
    } else {
      S += s[i][t[i]];
      L[t[i]] = i;
    }
    REP(j, 27) { S -= c[j] * (i - L[j]); }
  }
  return S;
}

int saga(int d, vector<int> &L) {
  int S = 0;
  REP(i, 27) { S += c[i] * (d - L[i]); }
  return S;
}

int main() {
  cin >> D;
  D++;
  REP(i, 27) { cin >> c[i]; }
  REP(i, D) {
    REP(j, 27) { cin >> s[i][j]; }
  }
  vector<int> t(D), last(27, 0);

  REP(i, D) {
    int a = 1, S = -1000000, u = 0;
    REP(j, 27) {
      u = s[i][j];
      u -= saga(i, last);
      u += c[j] * (i - last[j]);
      if (S < u) {
        a = j;
        S = u;
      }
    }
    t[i] = a;
    last[a] = i;
  }
  int S = sco(t, 0, 0), T = 0, n = 0;
  REP(i, D) {
    REP(j, 27) {
      T = sco(t, i, j);
      if (S < T) {
        t[i] = j;
        S = T;
        if (n <= 125) {
          i = 1;
          n++;
          break;
        }
      }
    }
  }

  REP(i, D) { cout << t[i] << "\\n"; }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
int D, c[27], s[366][27];

int sco(vector<int> &t, int k, int x) {
  int S = 0, L[27] = {};
  REP(i, D) {
    if (i == k) {
      S += s[i][x];
      L[x] = i;
    } else {
      S += s[i][t[i]];
      L[t[i]] = i;
    }
    REP(j, 27) { S -= c[j] * (i - L[j]); }
  }
  return S;
}

int saga(int d, vector<int> &L) {
  int S = 0;
  REP(i, 27) { S += c[i] * (d - L[i]); }
  return S;
}

int main() {
  cin >> D;
  D++;
  REP(i, 27) { cin >> c[i]; }
  REP(i, D) {
    REP(j, 27) { cin >> s[i][j]; }
  }
  vector<int> t(D), last(27, 0);

  REP(i, D) {
    int a = 1, S = -1000000, u = 0;
    REP(j, 27) {
      u = s[i][j];
      u -= saga(i, last);
      u += c[j] * (i - last[j]);
      if (S < u) {
        a = j;
        S = u;
      }
    }
    t[i] = a;
    last[a] = i;
  }
  int S = sco(t, 0, 0), T = 0, n = 0;
  REP(i, D) {
    REP(j, 27) {
      T = sco(t, i, j);
      if (S < T) {
        t[i] = j;
        S = T;
        if (n <= 140) {
          i = 1;
          n++;
          break;
        }
      }
    }
  }

  REP(i, D) { cout << t[i] << "\\n"; }
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  int d;
  cin >> d;
  const int n = 26;
  vector<int> c(n);
  vector<vector<int>> s(d, vector<int>(n));
  rep(i, n) cin >> c[i];
  rep(i, d) rep(j, n) cin >> s[i][j];
  vector<int> t(d), last(n);

  // 貪欲
  ll ans = 0;
  rep(i, d) {
    ll mx = -1001001001;
    int now = 0;

    rep(j, n) {
      ll tmp = ans;
      tmp += s[i][j];
      rep(k, n) {
        if (j == k)
          continue;
        tmp -= c[k] * (i + 1 - last[k]);
      }
      if (mx < tmp) {
        mx = tmp;
        now = j;
      }
    }
    ans = mx;
    last[now] = i + 1;
    t[i] = now + 1;
  }
  int cnt = 0;
  while (1) {
    // 局所探索法
    cnt++;
    if (cnt > 100000)
      break;
    int nd = rand() % d;
    int nq = rand() % n + 1;
    int old = t[nd];
    t[nd] = nq;

    // 点数のシミュレーション
    vector<int> nlast(n);
    ll now = 0;
    rep(i, d) {
      now += s[i][t[i]];
      nlast[t[i] - 1] = i + 1;
      rep(j, n) { now -= c[j] * (i + 1 - nlast[j - 1]); }
    }

    // 良くなれば更新
    if (now > ans) {
      ans = now;
    } else {
      t[nd] = old;
    }
  }

  rep(i, d) printf("%d\\n", t[i]);
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  int d;
  cin >> d;
  const int n = 26;
  vector<int> c(n);
  vector<vector<int>> s(d, vector<int>(n));
  rep(i, n) cin >> c[i];
  rep(i, d) rep(j, n) cin >> s[i][j];
  vector<int> t(d), last(n);

  ll ans = 0;
  rep(i, d) {
    ll mx = -1001001001;
    int now = 0;

    rep(j, n) {
      ll tmp = ans;
      tmp += s[i][j];
      rep(k, n) {
        if (j == k)
          continue;
        tmp -= c[k] * (i + 1 - last[k]);
      }
      if (mx < tmp) {
        mx = tmp;
        now = j;
      }
    }
    ans = mx;
    last[now] = i + 1;
    t[i] = now + 1;
  }
  int cnt = 0;
  while (1) {
    cnt++;
    if (cnt > 100000)
      break;
    int nd = rand() % d;
    int nq = rand() % n;
    int old = t[nd];
    t[nd] = nq;

    vector<int> nlast(n);
    ll now = 0;
    rep(i, d) {
      now += s[i][t[i]];
      nlast[t[i]] = i + 1;
      rep(j, n) { now -= c[j] * (i + 1 - nlast[j]); }
    }
    if (now > ans) {
      ans = now;
    } else {
      t[nd] = old;
    }
  }

  rep(i, d) printf("%d\\n", t[i]);
  return 0;
}
Problem p02618 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int solver(vector<int> c, vector<vector<int>> s, vector<int> t) {
  vector<int> last(26);
  ll st = 0, los = 0;
  REP(i, 365) {
    st += s[i][t[i] - 1];
    last[t[i] - 1] = i + 1;
    // cout << st << endl;   //満足度の低下を考えない場合
    REP(j, 365) { los += c[j] * (i + 1 - last[j]); }
    // cout << st << endl;
  }
  return st - los;
}

int main() {
  int D;
  cin >> D;
  vector<int> c(26);
  vector<vector<int>> s(D, vector<int>(26));

  /// 入力部分 ///
  REP(i, 26) { cin >> c[i]; }
  REP(i, D) {
    REP(j, 26) { cin >> s[i][j]; }
  }
  /// 入力部終わり ///

  random_device rnd;
  mt19937 mt(rnd());
  uniform_real_distribution<> rand(1, 27);

  vector<int> t(365);
  vector<int> best(365);
  ll st = 0, st_temp;
  int iii = 0;
  while (iii < 15e+2) {
    for (int i = 0; i < 365; ++i) {
      t[i] = int(rand(mt));
      // cout << t[i] << endl;
    }

    st_temp = solver(c, s, t);
    // cout << st_temp << endl;
    if (st < st_temp) {
      st = st_temp;
      best = t;
    }
    iii++;
  }
  REP(i, D) { cout << best[i] << endl; }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int solver(vector<int> c, vector<vector<int>> s, vector<int> t) {
  vector<int> last(26);
  ll st = 0, los = 0;
  REP(i, 5) {
    st += s[i][t[i] - 1];
    last[t[i] - 1] = i + 1;
    // cout << st << endl;   //満足度の低下を考えない場合
    REP(j, 26) { los += c[j] * (i + 1 - last[j]); }
    // cout << st << endl;
  }
  return st - los;
}

int main() {
  int D;
  cin >> D;
  vector<int> c(26);
  vector<vector<int>> s(D, vector<int>(26));

  /// 入力部分 ///
  REP(i, 26) { cin >> c[i]; }
  REP(i, D) {
    REP(j, 26) { cin >> s[i][j]; }
  }
  /// 入力部終わり ///

  random_device rnd; // 非決定的な乱数生成器を生成
  mt19937 mt(rnd()); //  メルセンヌ・ツイスタの32ビット版、引数は初期シード値
  uniform_real_distribution<> rand(1, 27); // [1.0, 2.0] 範囲の一様乱数

  vector<int> t(5);
  vector<int> best(5);
  ll st = 0, st_temp;
  int iii = 0;
  while (iii < 15e+4) {
    for (int i = 0; i < 5; ++i) {
      t[i] = int(rand(mt));
      // cout << t[i] << endl;
    }

    st_temp = solver(c, s, t);
    // cout << st_temp << endl;
    if (st < st_temp) {
      st = st_temp;
      best = t;
    }
    iii++;
  }
  REP(i, D) { cout << best[i] << endl; }
}
Problem p02618 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define MOD 1000000007
#define f(i, n) for (int i = 0; i < int(n); i++)
#define N 2600
int a[N][27];
int a2[N][27];
int e[N][365];
int v[N][365];
int sz, sz2;

int main() {
  int n;
  int x, y;
  vector<pair<int, pair<int, int>>> b;
  int c[26];
  int d[365][26];
  int ans[365];
  scanf("%d", &n);
  f(i, 26) scanf("%d", &c[i]);
  f(i, n) { f(j, 26) scanf("%d", &d[i][j]); }
  sz = 1;
  f(i, 26) a[0][i] = -1;
  a[0][26] = 0;
  f(t, n) {
    b.clear();
    f(i, sz) {
      x = a[i][26];
      f(j, 26) { x -= ((t - a[i][j]) * c[j]); }
      f(j, 26) {
        y = x + d[t][j];
        y += ((t - a[i][j]) * c[j]);
        b.push_back(make_pair(y, make_pair(i, j)));
      }
    }
    sort(b.begin(), b.end(), greater<pair<int, pair<int, int>>>());
    sz2 = b.size();
    if (sz2 > N)
      sz2 = N;
    f(i, sz2) {
      x = b[i].second.first;
      y = b[i].second.second;
      a2[i][26] = b[i].first;
      f(j, 26) a2[i][j] = a[x][j];
      a2[i][y] = t;
      e[i][t] = x;
      v[i][t] = y;
    }
    f(i, sz2) { f(j, 27) a[i][j] = a2[i][j]; }
    sz = sz2;
  }
  x = 0;
  for (int i = n - 1; i >= 0; i--) {
    ans[i] = v[x][i];
    x = e[x][i];
  }
  f(i, n) printf("%d\\n", ans[i] + 1);

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define MOD 1000000007
#define f(i, n) for (int i = 0; i < int(n); i++)
#define N 2750
int a[N][27];
int a2[N][27];
int e[N][365];
int v[N][365];
int sz, sz2;

int main() {
  int n;
  int x, y;
  vector<pair<int, pair<int, int>>> b;
  int c[26];
  int d[365][26];
  int ans[365];
  scanf("%d", &n);
  f(i, 26) scanf("%d", &c[i]);
  f(i, n) { f(j, 26) scanf("%d", &d[i][j]); }
  sz = 1;
  f(i, 26) a[0][i] = -1;
  a[0][26] = 0;
  f(t, n) {
    b.clear();
    f(i, sz) {
      x = a[i][26];
      f(j, 26) { x -= ((t - a[i][j]) * c[j]); }
      f(j, 26) {
        y = x + d[t][j];
        y += ((t - a[i][j]) * c[j]);
        b.push_back(make_pair(y, make_pair(i, j)));
      }
    }
    sort(b.begin(), b.end(), greater<pair<int, pair<int, int>>>());
    sz2 = b.size();
    if (sz2 > N)
      sz2 = N;
    f(i, sz2) {
      x = b[i].second.first;
      y = b[i].second.second;
      a2[i][26] = b[i].first;
      f(j, 26) a2[i][j] = a[x][j];
      a2[i][y] = t;
      e[i][t] = x;
      v[i][t] = y;
    }
    f(i, sz2) { f(j, 27) a[i][j] = a2[i][j]; }
    sz = sz2;
  }
  x = 0;
  for (int i = n - 1; i >= 0; i--) {
    ans[i] = v[x][i];
    x = e[x][i];
  }
  f(i, n) printf("%d\\n", ans[i] + 1);

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define pb push_back
#define mp make_pair
#define ms memset
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define lower_bound lb
#define upper_bound ub

int main() {
  int D;
  cin >> D;
  int C[27];
  FOR(i, 1, 26) cin >> C[i];
  int S[D + 1][27];
  FOR(i, 1, D) { FOR(j, 1, 26) cin >> S[i][j]; }
  int T[D + 1][1000];
  int last[27];
  ms(last, 0, sizeof(last));
  FOR(i, 1, D) {
    int max_index = 1;
    int maxi = S[i][1] + C[i] * (i - last[1]);
    FOR(j, 2, 26) {
      ll s = S[i][j] + C[j] * (i - last[j]);
      if (maxi < s) {
        maxi = s;
        max_index = j;
      }
    }
    last[max_index] = i;
    T[i][0] = max_index;
  }
  ll sat = 0;
  int d = 1;
  int q = T[1][0];
  int maxim = 1;
  ll max_sat = -10000000;
  FOR(_, 1, 10000) {
    FOR(i, 1, D) T[i][_] = T[i][_ - 1];
    T[d][_] = q;
    d = rand() % 365 + 1;
    q = rand() % 26 + 1;
    ms(last, 0, sizeof(last));
    sat = 0;
    FOR(i, 1, D) {
      last[T[i][_]] = i;
      sat += S[i][T[i][_]];
      FOR(j, 1, 26) sat -= C[j] * (i - last[j]);
    }
    if (sat > max_sat) {
      max_sat = sat;
      maxim = _;
    }
  }
  FOR(i, 1, D) { cout << T[i][maxim] << '\\n'; }

  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define pb push_back
#define mp make_pair
#define ms memset
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define lower_bound lb
#define upper_bound ub

void setIO(string name) {
  freopen((name + ".in").c_str(), "r", stdin);
  freopen((name + ".out").c_str(), "w", stdout);
  ios_base::sync_with_stdio(0);
}
int main() {
  setIO("sample2");
  int D;
  cin >> D;
  int C[27];
  FOR(i, 1, 26) cin >> C[i];
  int S[D + 1][27];
  FOR(i, 1, D) { FOR(j, 1, 26) cin >> S[i][j]; }
  int T[D + 1][1000];
  int last[27];
  ms(last, 0, sizeof(last));
  FOR(i, 1, D) {
    int max_index = 1;
    int maxi = S[i][1] + C[i] * (i - last[1]);
    FOR(j, 2, 26) {
      ll s = S[i][j] + C[j] * (i - last[j]);
      if (maxi < s) {
        maxi = s;
        max_index = j;
      }
    }
    last[max_index] = i;
    T[i][0] = max_index;
  }
  ll sat = 0;
  int d = 1;
  int q = T[1][0];
  int maxim = 1;
  ll max_sat = -10000000;
  FOR(_, 1, 10000) {
    FOR(i, 1, D) T[i][_] = T[i][_ - 1];
    T[d][_] = q;
    d = rand() % 365 + 1;
    q = rand() % 26 + 1;
    ms(last, 0, sizeof(last));
    sat = 0;
    FOR(i, 1, D) {
      last[T[i][_]] = i;
      sat += S[i][T[i][_]];
      FOR(j, 1, 26) sat -= C[j] * (i - last[j]);
    }
    if (sat > max_sat) {
      max_sat = sat;
      maxim = _;
    }
  }
  FOR(i, 1, D) { cout << T[i][maxim] << '\\n'; }

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int F = 26;
const int def = 1e6;

int n;
vector<int> c(F);
vector<vector<int>> a;

void init() {
  cin >> n;
  a.resize(n, vector<int>(F));
  for (int i = 0; i < F; i++)
    cin >> c[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < F; j++)
      cin >> a[i][j];
}

vector<int> calc(int rng) {
  vector<int> last(F, -1);
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    vector<int> cur = a[i];
    for (int j = 0; j < F; j++)
      cur[j] += (i - last[j]) * (c[j] + rng);
    int ind = max_element(cur.begin(), cur.end()) - cur.begin();
    last[ind] = i;
    ans.emplace_back(ind);
  }
  return ans;
}

int chack(vector<int> p) {
  int sum = 0;
  vector<int> last(F, -1);
  for (int i = 0; i < n; i++) {
    sum += a[i][p[i]];
    last[p[i]] = i;
    for (int j = 0; j < F; j++)
      sum -= (i - last[j]) * c[j];
  }
  return sum;
}

int main() {
  srand((unsigned)time(NULL));
  init();

  vector<int> ans;
  int M = 4 * 1e4, nax = -1e9;
  for (int I = 1; I <= M; I++) {
    int sed = rand() % (rand() % ((I / 50) + 1) + 1) * ((rand() % 2) ? 1 : -1);
    vector<int> cur = calc(sed);
    int k = chack(cur);
    if (k > nax) {
      nax = k;
      ans = cur;
    }
  }

  for (auto i : ans)
    cout << i + 1 << endl;
}

/*
satisfaction: 424801
score: 1424801
*/


Error: -8

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int F = 26;
const int def = 1e6;

int n;
vector<int> c(F);
vector<vector<int>> a;

void init() {
  cin >> n;
  a.resize(n, vector<int>(F));
  for (int i = 0; i < F; i++)
    cin >> c[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < F; j++)
      cin >> a[i][j];
}

vector<int> calc(int rng) {
  vector<int> last(F, -1);
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    vector<int> cur = a[i];
    for (int j = 0; j < F; j++)
      cur[j] += (i - last[j]) * (c[j] + rng);
    int ind = max_element(cur.begin(), cur.end()) - cur.begin();
    last[ind] = i;
    ans.emplace_back(ind);
  }
  return ans;
}

int chack(vector<int> p) {
  int sum = 0;
  vector<int> last(F, -1);
  for (int i = 0; i < n; i++) {
    sum += a[i][p[i]];
    last[p[i]] = i;
    for (int j = 0; j < F; j++)
      sum -= (i - last[j]) * c[j];
  }
  return sum;
}

int main() {
  srand((unsigned)time(NULL));
  init();

  vector<int> ans;
  int M = 4 * 1e4, nax = -1e9;
  for (int I = 1; I <= M; I++) {
    int sed = rand() % (rand() % ((I / 50) + 1)) * ((rand() % 2) ? 1 : -1);
    vector<int> cur = calc(sed);
    int k = chack(cur);
    if (k > nax) {
      nax = k;
      ans = cur;
    }
  }

  for (auto i : ans)
    cout << i + 1 << endl;
}

/*
satisfaction: 424801
score: 1424801
*/