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

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli, lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout << (bool x ? "Yes" : "No") << endl;
#define out(s) cout << s << endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(), s.end()
void vout(vi v) {
  for (int i = 0; i < v.size(); i++)
    cout << v.at(i) << endl;
}
int main() {
  vvi c(26, vi(2, 0));
  lli d;
  cin >> d;
  vvi s(26, vi(d));
  vi ans(d);
  rep(i, 26) cin >> c[i][0]; // c[i][1]には使われた日を記録
  rep(i, d) rep(j, 26) cin >> s[j][i];
  rep(i, d) {
    lli pi = 0;
    for (lli j = 0; j < 26; j++) {
      pi -= c[j][0] * (i - c[j][1]);
    }
    lli sum = -INF;
    lli prev = -INF;
    lli mem = 0;
    rep(j, 26) {
      sum = max(sum, pi + c[j][0] * (i - c[j][1]) + s[j][i]);
      if (sum != prev) {
        prev = sum;
        mem = j;
      }
    }
    c[mem][1] = i;
    ans[i] = mem + 1;
  }
  vout(ans);
}

Error: 0

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli, lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout << (bool x ? "Yes" : "No") << endl;
#define out(s) cout << s << endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(), s.end()
void vout(vi v) {
  for (int i = 0; i < v.size(); i++)
    cout << v.at(i) << endl;
}
int main() {

  vvi c(26, vi(2, 0));
  lli d;
  cin >> d;
  vvi s(26, vi(d));
  vi ans(d);
  rep(i, 26) cin >> c[i][0]; // c[i][1]には使われた日を記録
  rep(i, d) rep(j, 26) cin >> s[j][i];
  rep(i, d) {
    lli pi = 0;
    for (lli j = 0; j < 26; j++) {
      pi -= c[j][0] * (i - c[i][1]);
    }
    lli sum = -INF;
    lli prev = -INF;
    lli mem = 0;
    rep(j, 26) {
      sum = max(sum, pi + c[j][0] * (i - c[i][1]) + s[j][i]);
      if (sum != prev) {
        prev = sum;
        mem = j;
      }
    }
    c[mem][1] = i;
    ans[i] = mem + 1;
  }
  vout(ans);
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(c) (c).rbegin(), (c).rend()
#define mp make_pair
#define endl '\\n'
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll inf = 1e9 + 7;
const ll mod = 1e9 + 7;
signed 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> last(26);
  vector<ll> v(d);
  ll ans = 0;
  rep(i, d) {
    ll ma = -inf * inf;
    ll idx = 0;
    rep(t, 26) {
      ll cn = 0;
      cn += s[i][t];
      ll m = last[t];
      last[t] = i + 1;
      rep(j, 26) { cn -= c[j] * (i - last[j] + 1); }
      last[t] = m;
      if (cn > ma) {
        ma = cn;
        idx = t;
      }
    }
    ans += ma;
    last[idx] = i + 1;
    v[i] = idx + 1;
  }
  ll m = 10000;
  rep(o, m) {
    vector<ll> vv(d);
    rep(j, d) vv[j] = v[j];
    rep(i, 100) {
      ll a = rand() % d, b = rand() % 26;
      vv[a] = b + 1;
    }
    ll cnt = 0;
    vector<ll> la(26);
    rep(i, d) {
      ll t = vv[i] - 1;
      cnt += s[i][t];
      la[t] = i + 1;
      rep(j, 26) { cnt -= c[j] * (i - la[j] + 1); }
    }
    if (ans < cnt) {
      cnt = ans;
      rep(j, d) { v[j] = vv[j]; }
    }
  }
  rep(i, d) { cout << v[i] << endl; }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(c) (c).rbegin(), (c).rend()
#define mp make_pair
#define endl '\\n'
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll inf = 1e9 + 7;
const ll mod = 1e9 + 7;
signed 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> last(26);
  vector<ll> v(d);
  ll ans = 0;
  rep(i, d) {
    ll ma = -inf * inf;
    ll idx = 0;
    rep(t, 26) {
      ll cn = 0;
      cn += s[i][t];
      ll m = last[t];
      last[t] = i + 1;
      rep(j, 26) { cn -= c[j] * (i - last[j] + 1); }
      last[t] = m;
      if (cn > ma) {
        ma = cn;
        idx = t;
      }
    }
    ans += ma;
    last[idx] = i + 1;
    v[i] = idx + 1;
  }
  ll m = 10000;
  rep(o, m) {
    vector<ll> vv(d);
    rep(j, d) vv[j] = v[j];
    rep(i, 100) {
      ll a = rand() % d, b = rand() % 26;
      vv[a] = b;
    }
    ll cnt = 0;
    vector<ll> la(26);
    rep(i, d) {
      ll t = vv[i] - 1;
      cnt += s[i][t];
      la[t] = i + 1;
      rep(j, 26) { cnt -= c[j] * (i - la[j] + 1); }
    }
    if (ans < cnt) {
      cnt = ans;
      v = vv;
    }
  }
  rep(i, d) { cout << v[i] << endl; }
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(c) (c).rbegin(), (c).rend()
#define mp make_pair
#define endl '\\n'
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll inf = 1e9 + 7;
const ll mod = 1e9 + 7;
signed 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> last(26);
  vector<ll> v(d);
  ll ans = 0;
  rep(i, d) {
    ll ma = -inf * inf;
    ll idx = 0;
    rep(t, 26) {
      ll cn = 0;
      cn += s[i][t];
      ll m = last[t];
      last[t] = i + 1;
      cn += 5 * (d - last[t] + 1);
      last[t] = m;
      if (cn > ma) {
        ma = cn;
        idx = t;
      }
    }
    last[idx] = i + 1;
    v[i] = idx + 1;
  }
  rep(i, d) { cout << v[i] << endl; }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(c) (c).rbegin(), (c).rend()
#define mp make_pair
#define endl '\\n'
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll inf = 1e9 + 7;
const ll mod = 1e9 + 7;
signed 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> last(26);
  vector<ll> v(d);
  vector<pair<ll, pll>> q(0);
  rep(i, d) {
    rep(j, 26) { q.pb(mp(c[j] * (d - abs(i - d / 2)) * s[i][j], mp(i, j))); }
  }
  sort(rall(q));
  ll ans = 0;
  rep(zz, 365) {
    ll cnt = 0;
    vector<ll> vv(d);
    rep(o, 50) {
      ll x = rand() % 200;
      ll a = q[x].second.first;
      ll b = q[x].second.second;
      vv[a] = b + 1;
    }
    rep(i, d) {
      ll ma = -inf * inf;
      ll idx = 0;
      if (vv[i] > 0) {
        ll t = v[i] - 1;
        last[t] = i + 1;
        ma = s[i][t];
        rep(j, 26) { ma -= c[j] * (i - last[j] + 1); }
        cnt += ma;
        continue;
      }
      rep(t, 26) {
        ll cn = 0;
        cn += s[i][t];
        ll m = last[t];
        last[t] = i + 1;
        rep(j, 26) { cn -= c[j] * (i - last[j] + 1); }
        last[t] = m;
        if (cn > ma) {
          ma = cn;
          idx = t;
        }
      }
      cnt += ma;
      last[idx] = i + 1;
      vv[i] = idx + 1;
    }
    if (cnt > ans) {
      rep(i, d) { v[i] = vv[i]; }
    }
  }
  rep(i, d) { cout << v[i] << endl; }
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using pll = pair<long long, long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
const int d = 365;
// const int d = 5;
int c[26];
int s[d][26];
int last[26] = {0};

int score(vector<int> t) {
  vector<int> last(26, 0);
  int ans = 0;
  rep(i, d) {
    ans += s[i][t[i]];
    last[t[i]] = i + 1;
    rep(j, 26) ans -= c[j] * (i + 1 - last[j]);
    // cout << ans << endl;
  }
  return ans;
}

// day 1-index i_day 's contest is k
int nowscore(int i, int k) {
  int res = s[i][k];
  int before = last[k];
  last[k] = i + 1;
  rep(j, 26) res -= c[j] * (i + 1 - last[j]);
  last[k] = before;
  return res;
}

int main() {
  int tmp;
  cin >> tmp;
  rep(i, 26) cin >> c[i];
  rep(i, d) rep(j, 26) cin >> s[i][j];

  vector<int> ans(d, -1);
  for (int i = 0; i < d; i++) {
    int id = -1;
    int mx = -INF;
    for (int j = 0; j < 26; j++) {
      int res = nowscore(i, j);
      if (mx < res) {
        id = j;
        mx = res;
      }
      ans[i] = id;
      last[id] = i + 1;
    }
  }

  rep(i, d) cout << ans[i] + 1 << endl;
  // cout << score(ans) << endl;

  return 0;
}

Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using pll = pair<long long, long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
const int d = 365;
// const int d = 5;
int c[26];
int s[d][26];

int score(vector<int> t) {
  vector<int> last(26, 0);
  int ans = 0;
  rep(i, d) {
    ans += s[i][t[i] - 1];
    last[t[i] - 1] = i + 1;
    rep(j, 26) ans -= c[j] * (i + 1 - last[j]);
    cout << ans << endl;
  }
  return ans;
}

int main() {
  int tmp;
  cin >> tmp;
  rep(i, 26) cin >> c[i];
  rep(i, d) rep(j, 26) cin >> s[i][j];
  vector<int> t(d);
  rep(i, d) cin >> t[i];
  score(t);
  return 0;
}
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();

  for (int i = 364; i >= 0; i--) {
    int p = i;
    int tmp = t[i];
    for (int j = 0; j < 26; j++) {
      if (j == t[i])
        continue;
      t[i] = j;
      if (ans > p_calc())
        t[i] = 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;
}

inline void InitRand() { srand((unsigned int)time(NULL)); }

int main() {
  input();
  greedy();
  ll ans = p_calc();
  InitRand();
  rep(i, 10000000) {

    /////////////////////////////

    int p = rand() % 365;
    int q = rand() % 26;

    /////////////////////////////

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

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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  if (a == 0) {
    return b;
  }
  return a / gcd(a, b) * b;
}
template <class T> ll LBI(vector<T> &ar, T in) {
  return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T> ll UBI(vector<T> &ar, T in) {
  return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}

ll d, c[30] = {}, s[370][30] = {}, last[30] = {}, ans[370] = {};

int main() {
  cin >> d;
  rep(i, 26) cin >> c[i];
  rep(i, d) { rep(j, 26) cin >> s[i][j]; }
  rep(i, d) {
    ll satisfaction = -1000000, contest = 0;
    rep(j, 26) {
      if (satisfaction < s[i][j] - c[j] * (i - last[j])) {
        satisfaction = s[i][j] - c[j] * (i - last[j]);
        contest = j;
      }
      ans[i] = contest;
      last[contest] = i;
    }
  }
  rep(i, d) cout << ans[i] + 1 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  if (a == 0) {
    return b;
  }
  return a / gcd(a, b) * b;
}
template <class T> ll LBI(vector<T> &ar, T in) {
  return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T> ll UBI(vector<T> &ar, T in) {
  return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}

ll d, c[30] = {}, s[370][30] = {}, last[30] = {}, ans[370] = {};

int main() {
  cin >> d;
  rep(i, 26) cin >> c[i];
  rep(i, d) { rep(j, 26) cin >> s[i][j]; }
  rep(i, d) {
    ll satisfaction = -1000000, contest = 0;
    rep(j, 26) {
      if (satisfaction < s[i][j] - c[i] * (i - last[j])) {
        satisfaction = s[i][j] - c[i] * (i - last[j]);
        contest = j;
      }
      ans[i] = contest;
      last[contest] = i;
    }
  }
  rep(i, d) cout << ans[i] + 1 << endl;
  return 0;
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int d;
  vector<int> c(26);
  vector<vector<int>> s(d, vector<int>(26));
  cin >> d;
  vector<int> ans(d);
  vector<int> mx(d);
  rep(i, 26) { cin >> c.at(i); }
  rep(i, d) {
    rep(j, 26) {
      cin >> s[i][j];
      if (mx.at(i) < s[i][j]) {
        ans.at(i) = j + 1;
        mx.at(i) = s[i][j];
      }
    }
  }

  rep(i, d) { cout << ans.at(i) << endl; }
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int d;
  vector<int> c(26);
  vector<vector<int>> s(d, vector<int>(26));
  cin >> d;
  vector<int> ans(d);
  vector<int> mx(d);
  rep(i, 26) { cin >> c.at(i); }
  rep(i, 26) {
    rep(j, d) {
      cin >> s[i][j];
      if (mx.at(j) < s[i][j]) {
        ans.at(j) = i;
        mx.at(j) = s[i][j];
      }
    }
  }

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

#include <bits/stdc++.h>
#include <queue>
using namespace std;
int main() {
  int D;
  cin >> D;
  vector<int> les(26, 0);
  array<int, 26> c;
  for (int i = 0; i < 26; i++)
    cin >> c.at(i);
  for (int i = 0; i < D; i++) {
    array<int, 26> s;
    for (int j = 0; j < 26; j++) {
      cin >> s.at(j);
    }
    pair<int, int> t = make_pair(0, 0);
    int t_ = -1;
    for (int j = 0; j < 26; j++) {
      pair<int, int> kj = make_pair(s.at(j), -1 * c.at(j) * les.at(j));
      int p_ = j;
      if (t < kj) {
        t = kj;
        t_ = p_;
      } else if (t == kj && c.at(t_) < c.at(p_)) {
        t = kj;
        t_ = p_;
      }
    }
    cout << t_ + 1 << endl;
    for (int j = 0; j < 26; j++) {
      if (j == t_)
        les.at(j) = 0;
      else
        les.at(j)++;
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <queue>
using namespace std;
int main() {
  int D;
  cin >> D;
  vector<int> les(26, 0);
  int c[26];
  for (int i = 0; i < 26; i++)
    cin >> c[i];
  for (int i = 0; i < D; i++) {
    int s[26];
    for (int j = 0; j < 26; j++) {
      cin >> s[i];
    }
    pair<int, int> t = make_pair(0, 0);
    int t_ = -1;
    for (int j = 0; i < 26; j++) {
      pair<int, int> kj = make_pair(s[j], -c[j] * les[j]);
      int p_ = j;
      if (t < kj) {
        t = kj;
        t_ = p_;
      } else if (t == kj && c[t_] < c[p_]) {
        t = kj;
        t_ = p_;
      }
    }
    cout << t.first << endl;
    for (int j = 0; j < 26; j++) {
      if (j == t_)
        les[j] = 0;
      else
        les[j]++;
    }
  }
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
// #pragma GCC optimize("O3")
// #pragma GCC target ("sse4")
using namespace std;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define MEM(x, a) memset((x), a, sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
const long long MOD = (long long)(1e9 + 7);
const long long MMX = (long long)(1e18);
typedef long long LL;
typedef pair<int, int> pii;
int n, ls[30], mx1, mx2, x, c[30];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 26; i++)
    scanf("%d", &c[i]), ls[i] = 0;
  for (int i = 1; i <= n; i++) {
    mx1 = 0, mx2 = 1;
    for (int j = 1; j <= 26; j++) {
      scanf("%d", &x);
      if (mx1 < (i - ls[j]) * c[j])
        mx1 = (i - ls[j]) * c[j], mx2 = j;
      else if (mx1 == (i - ls[j]) * c[j])
        if (ls[j] < ls[mx2])
          mx2 = j;
    }
    // printf("[%d]",mx1);
    ls[mx2] = i;
    printf("%d\\n", mx2);
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
// #pragma GCC optimize("O3")
// #pragma GCC target ("sse4")
using namespace std;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define MEM(x, a) memset((x), a, sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
const long long MOD = (long long)(1e9 + 7);
const long long MMX = (long long)(1e18);
typedef long long LL;
typedef pair<int, int> pii;
int n, ls[30], mx1, mx2, x, c[30];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &c[i]);
  for (int i = 1; i <= n; i++) {
    mx1 = 0;
    for (int j = 1; j <= 26; j++) {
      scanf("%d", &x);
      if (mx1 < (i - ls[j]) * c[i])
        mx1 = (i - ls[j]) * c[i], mx2 = j;
      else if (mx1 == (i - ls[j]) * c[i])
        if (ls[j] < ls[mx2])
          mx2 = j;
    }
    // printf("[%d]",mx1);
    ls[mx2] = i;
    printf("%d\\n", mx2);
  }
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

const char nl = '\\n';

void solve() {
  int d;
  cin >> d;
  vector<int> c;
  for (int i = 0; i < 26; ++i) {
    int val;
    cin >> val;
    c.push_back(val);
  }
  for (int i = 0; i < d; ++i) {
    map<int, int, greater<int>> m;
    for (int j = 0; j < 26; ++j) {
      int val;
      cin >> val;
      m[val / max(c[j], 1)] = j + 1;
    }
    cout << m.begin()->second << nl;
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  solve();
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

const char nl = '\\n';

void solve() {
  int d;
  cin >> d;
  vector<int> c;
  for (int i = 0; i < 26; ++i) {
    int val;
    cin >> val;
    c.push_back(val);
  }
  for (int i = 0; i < d; ++i) {
    map<int, int, greater<int>> m;
    for (int j = 0; j < 26; ++j) {
      int val;
      cin >> val;
      m[val / c[j]] = j + 1;
    }
    cout << m.begin()->second << nl;
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  solve();
  return 0;
}