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

#include <cstdio>
#include <cstdlib>
#include <ctime>
int last[500];
long long s[500][30];
long long c[30];
int tt[500];
int out[500];
int vis[30];

long long getD(int d) {
  for (int i = 1; i <= 26; i++)
    last[i] = 0;
  long long cur = 0;
  for (int i = 1; i <= d; i++) {
    int t = tt[i];
    cur += s[i][t];
    last[t] = i;
    for (int j = 1; j <= 26; j++)
      cur -= c[j] * (i - last[j]);
  }
  return cur;
}

int main() {
  srand(time(NULL));
  int d;
  scanf("%d", &d);
  for (int i = 1; i <= 26; i++)
    scanf("%lld", &c[i]);
  for (int i = 1; i <= d; i++) {
    for (int j = 1; j <= 26; j++)
      scanf("%lld", &s[i][j]);
  }
  for (int i = 1; i <= d; i++) {
    int find = 1;
    for (int j = 2; j <= 26; j++)
      if (s[i][j] > s[i][find])
        find = j;
    tt[i] = find;
  }
  long long ans = getD(d);
  for (int i = 0; i < 5000; i++) {
    int a = rand() % 365 + 1;
    int keep = tt[a];
    for (int j = 1; j <= 26; j++)
      vis[j] = 0;
    for (int j = 1; j <= 10; j++) {
      int u = rand() % 26 + 1;
      tt[a] = u;
      long long res = getD(d);
      if (res > ans) {
        keep = u;
        ans = res;
      }
    }
    tt[a] = keep;
  }
  for (int i = 1; i <= d; i++)
    printf("%d\\n", tt[i]);

  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <ctime>
int last[500];
long long s[500][30];
long long c[30];
int tt[500];
int out[500];

long long getD(int d) {
  for (int i = 1; i <= 26; i++)
    last[i] = 0;
  long long cur = 0;
  for (int i = 1; i <= d; i++) {
    int t = tt[i];
    cur += s[i][t];
    last[t] = i;
    for (int j = 1; j <= 26; j++)
      cur -= c[j] * (i - last[j]);
  }
  return cur;
}

int main() {
  srand(time(NULL));
  int d;
  scanf("%d", &d);
  for (int i = 1; i <= 26; i++)
    scanf("%lld", &c[i]);
  for (int i = 1; i <= d; i++) {
    for (int j = 1; j <= 26; j++)
      scanf("%lld", &s[i][j]);
  }
  for (int i = 1; i <= d; i++) {
    int find = 1;
    for (int j = 2; j <= 26; j++)
      if (s[i][j] > s[i][find])
        find = j;
    tt[i] = find;
  }
  long long ans = getD(d);
  for (int i = 0; i < 10000; i++) {
    int a = rand() % 365 + 1;
    int keep = tt[a];
    for (int j = 1; j <= 26; j++) {
      tt[a] = j;
      long long res = getD(d);
      if (res > ans) {
        keep = j;
        ans = res;
      }
    }
    tt[a] = keep;
  }
  for (int i = 1; i <= d; i++)
    printf("%d\\n", tt[i]);

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

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

int get_rand(int a, int b) { // [a, b]
  return uniform_int_distribution<int>(a, b)(rng);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int d, n = 26;
  cin >> d;
  vector<int> c(n);
  vector<vector<int>> s(d, vector<int>(n));
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < n; j++) {
      cin >> s[i][j];
    }
  }

  vector<int> t(d, -1);
  vector<int> last(n, -1);
  int res = 0;
  for (int i = 0; i < d; i++) {
    int z = -2e9;
    for (int k = 0; k < n; k++) {
      int y = 0;
      for (int j = 0; j < n; j++) {
        if (j == k) {
          y += s[i][j];
        } else {
          y -= (i - last[j]) * c[j];
        }
      }
      if (y > z) {
        z = y;
        t[i] = k;
      }
    }
    res += z;
    last[t[i]] = i;
    // cout << res << '\\n';
    cout << t[i] + 1 << '\\n';
  }

  // vector<int> t(d);
  // int m;
  // for (int i = 0; i < d; i++) {
  //     cin >> t[i];
  //     t[i]--;
  // }
  // cin >> m;
  // while (m--) {
  //     int dd, qq;
  //     cin >> dd >> qq;
  //     dd--, qq--;
  //     t[dd] = qq;
  //     int res = 0;
  //     vector<int> last(n, -1);
  //     for (int i = 0; i < d; i++) {
  //         res += s[i][t[i]];
  //         int x = i - last[t[i]] - 1;
  //         res -= x * (x + 1) / 2;
  //         last[t[i]] = i;
  //     }
  //     cout << res << '\\n';
  // }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

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

int get_rand(int a, int b) { // [a, b]
  return uniform_int_distribution<int>(a, b)(rng);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int d, n = 26;
  cin >> d;
  vector<int> c(n);
  vector<vector<int>> s(d, vector<int>(n));
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < n; j++) {
      cin >> s[i][j];
    }
  }
  vector<int> t(n, -1);
  vector<int> last(n, -1);
  int res = 0;
  for (int i = 0; i < d; i++) {
    int z = -2e9;
    for (int k = 0; k < n; k++) {
      int y = 0;
      for (int j = 0; j < n; j++) {
        if (j == k) {
          y += s[i][j];
        } else {
          y -= (i - last[j]) * c[j];
        }
      }
      if (y > z) {
        z = y;
        t[i] = k;
      }
    }
    res += z;
    last[t[i]] = i;
    // cout << res << '\\n';
    cout << t[i] + 1 << '\\n';
  }
  return 0;
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

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

int get_rand(int a, int b) { // [a, b]
  return uniform_int_distribution<int>(a, b)(rng);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int d, n = 26;
  cin >> d;
  // d = 365;
  vector<int> c(n);
  vector<vector<int>> s(d, vector<int>(n));
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    // c[i] = get_rand(0, 100);
  }
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < n; j++) {
      cin >> s[i][j];
      // s[i][j] = get_rand(0, 20000);
    }
  }
  vector<int> t(d);
  for (int i = 0; i < d; i++) {
    t[i] = get_rand(0, n - 1);
  }
  auto get = [&]() {
    int res = 0;
    vector<int> last(n, -1);
    for (int i = 0; i < d; i++) {
      res += s[i][t[i]];
      int x = i - last[t[i]] - 1;
      res -= c[t[i]] * x * (x + 1) / 2;
      last[t[i]] = i;
    }
    for (int i = 0; i < n; i++) {
      int x = d - last[i] - 1;
      res -= c[i] * x * (x + 1) / 2;
    }
    return res;
  };
  auto beg = clock();
  int cnt = 0;
  while (true) {
    cnt++;
    if (clock() - beg > 1900000) {
      break;
    }
    int q = get_rand(0, d - 1);
    int sc = -1e9;
    int best = -1;
    for (int i = 0; i < n; i++) {
      t[q] = i;
      int p = get();
      if (p > sc) {
        sc = p;
        best = i;
      }
    }
    t[q] = best;
  }
  for (int i = 0; i < d; i++) {
    cout << t[i] + 1 << '\\n';
  }
  debug(get());
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

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

int get_rand(int a, int b) { // [a, b]
  return uniform_int_distribution<int>(a, b)(rng);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int d, n = 26;
  cin >> d;
  vector<int> c(n);
  vector<vector<int>> s(d, vector<int>(n));
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < n; j++) {
      cin >> s[i][j];
    }
  }
  vector<int> t(d);
  for (int i = 0; i < d; i++) {
    t[i] = get_rand(0, d - 1);
  }
  auto get = [&]() {
    int res = 0;
    vector<int> last(n, -1);
    for (int i = 0; i < d; i++) {
      res += s[i][t[i]];
      int x = i - last[t[i]] - 1;
      res -= c[t[i]] * x * (x + 1) / 2;
      last[t[i]] = i;
    }
    for (int i = 0; i < n; i++) {
      int x = d - last[i] - 1;
      res -= c[i] * x * (x + 1) / 2;
    }
    return res;
  };
  auto beg = clock();
  int cnt = 0;
  while (true) {
    cnt++;
    if (clock() - beg > 1900000) {
      break;
    }
    int q = get_rand(0, d - 1);
    int sc = -1e9;
    int best = -1;
    for (int i = 0; i < n; i++) {
      t[q] = i;
      int p = get();
      if (p > sc) {
        sc = p;
        best = i;
      }
    }
    t[q] = best;
  }
  for (int i = 0; i < d; i++) {
    cout << t[i] + 1 << '\\n';
  }
  debug(get());
  return 0;
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int d;
  // int n=0;//
  cin >> d;
  int c[26];
  int s[d][26];
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
    // n+=c[i];//
  }
  for (int i = 0; i < d; i++) {
    for (int ii = 0; ii < 26; ii++) {
      cin >> s[i][ii];
    }
  }
  long long int la[d];
  int lad[26];
  for (int i = 0; i < 26; i++) {
    lad[i] = -1;
  }
  int mm, md;
  // long long int m=0;//満足度確認用
  for (int i = 0; i < d; i++) {
    md = 0;
    // la[i]=(n-c[0])*(-i-1)+s[i][0];//
    la[i] = s[i][0];
    for (int ii = 1; ii < 26; ii++) {
      la[i] -= (i - lad[ii]) * c[ii];
    }
    for (int ii = 1; ii < 26; ii++) {
      // mm=(n-c[ii])*(-i-1)+s[i][ii];//
      mm = s[i][ii];
      for (int iii = 0; iii < 26; iii++) {
        if (ii != iii)
          mm -= (i - lad[iii]) * c[iii];
      }
      if ((la[i] < mm) || (la[i] == mm && c[md] < c[ii])) {
        la[i] = mm;
        md = ii;
      }
    }
    lad[md] = i;
    cout << md + 1 << endl;
    // m+=la[i];//満足度確認用
    // cout<<m<<endl;//満足度確認用
  }
  // cout<<m<<endl;//満足度確認用
  // cout<<n<<endl;//
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int d;
  // int n=0;//
  cin >> d;
  int c[26];
  int s[d][26];
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
    // n+=c[i];//
  }
  for (int i = 0; i < d; i++) {
    for (int ii = 0; ii < 26; ii++) {
      cin >> s[i][ii];
    }
  }
  long long int la[26];
  int lad[26];
  for (int i = 0; i < 26; i++) {
    lad[i] = -1;
  }
  int mm, md;
  // long long int m=0;//満足度確認用
  for (int i = 0; i < d; i++) {
    md = 0;
    // la[i]=(n-c[0])*(-i-1)+s[i][0];//
    la[i] = s[i][0];
    for (int ii = 1; ii < 26; ii++) {
      la[i] -= (i - lad[ii]) * c[ii];
    }
    for (int ii = 1; ii < 26; ii++) {
      // mm=(n-c[ii])*(-i-1)+s[i][ii];//
      mm = s[i][ii];
      for (int iii = 0; iii < 26; iii++) {
        if (ii != iii)
          mm -= (i - lad[iii]) * c[iii];
      }
      if ((la[i] < mm) || (la[i] == mm && c[md] < c[ii])) {
        la[i] = mm;
        md = ii;
      }
    }
    lad[md] = i;
    cout << md + 1 << endl;
    // m+=la[i];//満足度確認用
    // cout<<m<<endl;//満足度確認用
  }
  // cout<<m<<endl;//満足度確認用
  // cout<<n<<endl;//
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
template <class A> void PR(A a, ll n) {
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << a[i];
  }
  cout << "\\n";
}
ld PI = 3.14159265358979323846;

int main() {
  ll D;
  cin >> D;
  vector<ll> c(26);
  rep(i, 26) { cin >> c[i]; }
  vector<vector<ll>> s(D, vector<ll>(26));
  rep(i, D) {
    rep(j, 26) { cin >> s[i][j]; }
  }
  vector<ll> t(D);
  /*rep(i,D){
      cin >> t[i];
      t[i]--;
  }*/

  ll score = 0;
  ll cur = 0;
  rep(i, D) {
    t[i] = ((cur % 26) + 1);
    cur++;
  }
  ll M = 0;
  vector<ll> ans(D);
  rep(j, 1000) {
    t[j % D]++;
    t[j % D] %= 26;
    score = 0;
    vector<ll> memo(26, -1);
    rep(i, D) {
      score += s[i][t[i]];
      memo[t[i]] = i;
      ll M = 0;
      rep(j, 26) {
        if (M < s[i][j]) {
          t[i] = j + 1;
          M = s[i][j];
        }
      }
    }
    if (M < score) {
      rep(k, D) { ans[k] = t[k]; }
    } else {
      t[j % D]--;
      t[j % D] %= 26;
    }
  }
  rep(i, D) { cout << ans[i] << endl; }
}


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
template <class A> void PR(A a, ll n) {
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << a[i];
  }
  cout << "\\n";
}
ld PI = 3.14159265358979323846;

int main() {
  ll D;
  cin >> D;
  vector<ll> c(26);
  rep(i, 26) { cin >> c[i]; }
  vector<vector<ll>> s(D, vector<ll>(26));
  rep(i, D) {
    rep(j, 26) { cin >> s[i][j]; }
  }
  vector<ll> t(D);
  /*rep(i,D){
      cin >> t[i];
      t[i]--;
  }*/
  vector<ll> memo(26, -1);
  ll score = 0;
  ll cur = 0;
  rep(i, D) {
    t[i] = ((cur % 26) + 1);
    cur++;
  }
  ll M = 0;
  vector<ll> ans(D);
  rep(j, 100) {
    t[j]++;
    score = 0;
    rep(i, D) {
      score += s[i][t[i]];
      memo[t[i]] = i;
      ll M = 0;
      rep(j, 26) {
        if (M < s[i][j]) {
          t[i] = j + 1;
          M = s[i][j];
        }
      }
    }
    if (M < score) {
      rep(k, D) { ans[k] = t[k]; }
    } else {
      t[j]--;
    }
  }
  rep(i, D) { cout << t[i] << endl; }
}
Problem p02618 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <stdlib.h>
using namespace std;

int D;
int cl[26];
int sl[400][26];

int scores(int tl[]) {
  int s = 0;
  int last[26];
  for (int i = 0; i < 26; i++) {
    last[i] = 0;
  }
  for (int d = 0; d < D; d++) {
    int t = tl[d] - 1;
    last[t] = d + 1;

    int ss = sl[d][t];
    for (int i = 0; i < 26; i++) {
      int c = cl[i];
      ss -= c * (d + 1 - last[i]);
    }
    s += ss;
  }
  return s;
}

int main() {
  cin >> D;
  for (int i = 0; i < 26; i++) {
    cin >> cl[i];
  }
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> sl[i][j];
    }
  }
  double beta = 1.0;

  int tl[400];
  for (int i = 0; i < 400; i++) {
    tl[i] = rand() % 26 + 1;
  }
  int s = scores(tl);
  for (int i = 0; i < 10000; i++) {
    int d = rand() % D + 1;
    int x = tl[d - 1];

    int e[26];
    for (int j = 0; j < 26; j++) {
      int q = j + 1;
      int x = tl[d - 1];
      tl[d - 1] = q;
      e[j] = scores(tl);
      tl[d - 1] = x;
    }

    double esum = 0.0;
    double es[26];
    for (int j = 0; j < 26; j++) {
      es[j] = -log(e[j]) / beta;
      esum += exp(es[j]);
    }
    double p = rand() / RAND_MAX;
    double ps = 0.0;
    for (int j = 0; j < 26; j++) {
      ps += es[j] / esum;
      if (ps > p) {
        tl[d - 1] = j + 1;
        break;
      }
    }
  }

  for (int i = 0; i < D; i++) {
    cout << tl[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdlib.h>
#include <vector>
using namespace std;

int D;
int cl[26];
int sl[400][26];

int scores(int tl[]) {
  int s = 0;
  int last[26];
  for (int i = 0; i < 26; i++) {
    last[i] = 0;
  }
  for (int d = 0; d < D; d++) {
    int t = tl[d] - 1;
    last[t] = d + 1;

    int ss = sl[d][t];
    for (int i = 0; i < 26; i++) {
      int c = cl[i];
      ss -= c * (d + 1 - last[i]);
    }
    s += ss;
  }
  return s;
}

int main() {
  cin >> D;
  for (int i = 0; i < 26; i++) {
    cin >> cl[i];
  }
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> sl[i][j];
    }
  }

  int tl[400];
  for (int i = 0; i < 400; i++) {
    tl[i] = rand() % 26 + 1;
  }
  int s = scores(tl);
  for (int i = 0; i < 1000000; i++) {
    int d = rand() % D + 1;
    int q = rand() % 26 + 1;
    int x = tl[d - 1];
    tl[d - 1] = q;
    int s2 = scores(tl);
    if (s2 > s) {
      s = s2;
    } else {
      tl[d - 1] = x;
    }
  }

  for (int i = 0; i < D; i++) {
    cout << tl[i] << endl;
  }
  return 0;
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  int D;
  scanf("%d", &D);
  int c[26], s[D][26], last[26], ans[D];
  for (int i = 0; i < 26; ++i)
    scanf("%d", &c[i]);
  for (int i = 0; i < D; ++i) {
    for (int j = 0; j < 26; ++j)
      scanf("%d", &s[i][j]);
  }
  fill_n(last, 26, -1);
  for (int i = 0; i < D; ++i) {
    int x = -1000000000, opt = 0;
    for (int j = 0; j < 26; ++j) {
      if (c[j] * (i - last[j]) + s[i][j] > x)
        x = c[j] * (i - last[j]) + s[i][j], opt = j;
    }
    last[opt] = i;
    ans[i] = opt;
  }
  for (int i = 0; i < D; ++i)
    printf("%d\\n", ans[i] + 1);
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  int D;
  scanf("%d", &D);
  int c[26], s[D][26], last[26], ans[D];
  for (int i = 0; i < 26; ++i)
    scanf("%d", &c[i]);
  for (int i = 0; i < D; ++i) {
    for (int j = 0; j < 26; ++j)
      scanf("%d", &s[i][j]);
  }
  fill_n(last, 26, -1);
  for (int i = 0; i < D; ++i) {
    int x = -1000000000, opt = 0;
    for (int j = 0; j < 26; ++j) {
      if (c[j] * (i - last[j]) + s[i][j] > x)
        x = c[j] * (i - last[j]) + s[i][j], opt = i;
    }
    last[opt] = i;
    ans[i] = opt;
  }
  for (int i = 0; i < D; ++i)
    printf("%d\\n", ans[i] + 1);
  return 0;
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll D;
  vector<ll> c(26);
  cin >> D;
  rep(i, 26) { cin >> c[i]; }
  vector<vector<ll>> s(D, vector<ll>(26));
  rep(i, D) {
    rep(j, 26) { cin >> s[i][j]; }
  }

  vector<ll> t(D, 0);
  // rep(i,D){cin >> t[i];}

  vector<ll> zenkai(26, 0);

  rep(i, D) {
    ll score = 0, zantei = -1102342, zanteisyu = 0;
    rep(j, 26) {
      score = 0;
      score += s[i][j];
      rep(k, 26) {
        if (j != k) {
          score -= c[j] * (i + 1 - zenkai[j]);
        }
      }
      if (score > zantei) {
        zantei = score;
        zanteisyu = j + 1;
      }
    }
    zenkai[zanteisyu - 1] = i + 1;
    cout << zanteisyu << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int D;
  vector<int> c(26);
  cin >> D;
  rep(i, 26) { cin >> c[i]; }
  vector<vector<int>> s(D, vector<int>(26));
  rep(i, D) {
    rep(j, 26) { cin >> s[i][j]; }
  }

  vector<int> t(D, 0);
  // rep(i,D){cin >> t[i];}

  vector<int> zenkai(26, 0);

  rep(i, D) {
    int score = 0, zantei = -1102342, zanteisyu = 0;
    rep(j, 26) {
      score = 0;
      score += s[i][j];
      rep(k, 26) {
        if (j != k) {
          score -= c[j] * (i + 1 - zenkai[j]);
        }
      }
      if (score > zantei) {
        zantei = score;
        zanteisyu = j + 1;
      }
    }
    zenkai[zanteisyu] = i + 1;
    cout << zanteisyu << endl;
  }
}
Problem p02619 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;

#define INF 1e+9
#define MAX_V 300

struct edge {
  int to;
  int cost;
};
using P = pair<ll, ll>;

int main() {
  ll d;
  cin >> d;
  vector<ll> c(26);
  vector<ll> t(d);
  vector<vector<ll>> s(d, vector<ll>(26));
  REP(i, 26) { cin >> c[i]; }
  REP(i, d) {
    REP(j, 26) { cin >> s[i][j]; }
  }
  REP(i, d) {
    cin >> t[i];
    t[i]--;
  }
  vector<ll> last(26, -1);
  ll score = 0;
  for (int day = 0; day < d; day++) {
    int contest_type = t[day];
    last[contest_type] = day;
    score += s[day][contest_type];
    for (int i = 0; i < 26; i++) {
      score = score - c[i] * (day - last[i]);
    }
    cout << score << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;

#define INF 1e+9
#define MAX_V 300

struct edge {
  int to;
  int cost;
};
using P = pair<ll, ll>;

int main() {
  ll d;
  cin >> d;
  vector<ll> c(26);
  vector<ll> t(26);
  vector<vector<ll>> s(d, vector<ll>(26));
  REP(i, 26) { cin >> c[i]; }
  REP(i, d) {
    REP(j, 26) { cin >> s[i][j]; }
  }
  REP(i, d) {
    cin >> t[i];
    t[i]--;
  }
  vector<ll> last(26, -1);
  ll score = 0;
  for (int day = 0; day < d; day++) {
    int contest_type = t[day];
    last[contest_type] = day;
    score += s[day][contest_type];
    for (int i = 0; i < 26; i++) {
      score = score - c[i] * (day - last[i]);
    }
    cout << score << endl;
  }
}
Problem p02619 (C++) — buggy submission, verdict: Runtime Error

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

constexpr int n = 365, m = 26;
int c[m], s[n][m];

int type[n];
int score(int lim = n) {
  static int last[m];
  fill(begin(last), end(last), -1);
  int res = 0;
  for (int i = 0; i < lim; ++i) {
    res += s[i][type[i]];
    last[type[i]] = i;
    for (int j = 0; j < m; ++j) {
      res -= c[j] * (i - last[j]);
    }
  }
  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  // cin.ignore();
  int _n;
  cin >> _n;
  assert(_n == n);
  for (int j = 0; j < m; ++j) {
    cin >> c[j];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    // cout << type[i] + 1 << '\\n';
    cin >> type[i];
    --type[i];
  }
  for (int i = 0; i < n; ++i) {
    cout << score(i + 1) << '\\n';
  }
}


Error: WA

Fixed submission:

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

constexpr int n = 365, m = 26;
int c[m], s[n][m];

int type[n];
int score(int lim = n) {
  static int last[m];
  fill(begin(last), end(last), -1);
  int res = 0;
  for (int i = 0; i < lim; ++i) {
    res += s[i][type[i]];
    last[type[i]] = i;
    for (int j = 0; j < m; ++j) {
      res -= c[j] * (i - last[j]);
    }
  }
  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin.ignore();
  for (int j = 0; j < m; ++j) {
    cin >> c[j];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    // cout << type[i] + 1 << '\\n';
    cin >> type[i];
    --type[i];
  }
  for (int i = 0; i < n; ++i) {
    cout << score(i + 1) << '\\n';
  }
}