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

#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#define rep(i, cc, n) for (int i = cc; i < n; ++i)
using namespace std;
using ll = long long;

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

  vector<int> C(26);
  vector<int> conts(26, 0);
  rep(i, 0, 26) {
    int c;
    cin >> c;

    C[i] = c;
  }

  vector<vector<int>> S(D, vector<int>(26));
  rep(i, 0, D) {
    rep(j, 0, 26) {
      int s;
      cin >> s;
      S.at(i).at(j) = s;
    }
  }

  rep(d, 1, D + 1) {
    int max = 0;
    int memo = 0;
    rep(j, 0, 26) {
      rep(k, 0, 26) {

        int satit = 0;
        if (k == j) {
          satit += S.at(d - 1).at(j);
        } else {
          satit -= C[j] * (d - conts[j]);
        }

        if (satit > max) {
          max = satit;
          memo = k;
        }
      }
    }
    cout << memo + 1 << endl;
    conts[memo] = d;
  }
}


Error: 0

Fixed submission:

#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#define rep(i, cc, n) for (int i = cc; i < n; ++i)
using namespace std;
using ll = long long;

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

  vector<int> C(26);
  vector<int> conts(26, 0);
  rep(i, 0, 26) {
    int c;
    cin >> c;

    C[i] = c;
  }

  vector<vector<int>> S(D, vector<int>(26));
  rep(i, 0, D) {
    rep(j, 0, 26) {
      int s;
      cin >> s;
      S.at(i).at(j) = s;
    }
  }

  rep(d, 1, D + 1) {
    int max = 0;
    int memo = 0;
    rep(j, 0, 26) {
      rep(k, 0, 26) {

        int satit = 0;
        if (k == j) {
          satit += S.at(d - 1).at(j);
        } else {
          satit -= C[j] * (d - conts[j]);
        }

        if (satit > max) {
          max = satit;
          memo = k;
        }
      }
    }
    cout << memo + 1 << endl;
    conts[d - 1] = memo;
  }
}
Problem p02618 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  cin >> D;
  for (int i = 0; i < 26; i++) {
    cin >> c.at(i).first;
    c.at(i).second = 0;
  }

  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s.at(i).at(j);
    }
  }

  for (int i = 0; i < D; i++) {
    t.at(i) = rand() % 26 + 1;
  }

  int count = 0;
  int S = 0;
  vector<int> ans(D);
  while (count++ < 50000) {

    t.at((rand() % D + 1) - 1) = rand() % 26 + 1;

    int Pl = 0;
    int Mi = 0;

    for (int i = 0; i < D; i++) {
      Pl += s.at(i).at(t.at(i) - 1);
      c.at(t.at(i) - 1).second = i + 1;
      for (int j = 0; j < 26; j++) {
        Mi += c.at(j).first * (i + 1 - c.at(j).second);
      }
      Pl -= Mi;
      Mi = 0;
    }
    if (S < Pl) {
      S = Pl;
      for (int i = 0; i < D; i++) {
        ans.at(i) = t.at(i);
      }
    } else if (S >= Pl) {
      continue;
    }
  }
  for (int i = 0; i < D; i++) {
    cout << ans.at(i) << endl;
  }
}


Error: TLE

Fixed submission:

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

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

  cin >> D;
  for (int i = 0; i < 26; i++) {
    cin >> c.at(i).first;
    c.at(i).second = 0;
  }

  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s.at(i).at(j);
    }
  }

  for (int i = 0; i < D; i++) {
    t.at(i) = rand() % 26 + 1;
  }

  int count = 0;
  int S = 0;
  vector<int> ans(D);
  while (count++ < 5000000) {

    t.at((rand() % D + 1) - 1) = rand() % 26 + 1;

    int Pl = 0;
    int Mi = 0;

    for (int i = 0; i < D; i++) {
      Pl += s.at(i).at(t.at(i) - 1);
      c.at(t.at(i) - 1).second = i + 1;
      for (int j = 0; j < 26; j++) {
        Mi += c.at(j).first * (i + 1 - c.at(j).second);
      }
      Pl -= Mi;
      Mi = 0;
    }
    if (S < Pl) {
      S = Pl;
      for (int i = 0; i < D; i++) {
        ans.at(i) = t.at(i);
      }
    } else if (S >= Pl) {
      continue;
    }
  }
  for (int i = 0; i < D; i++) {
    cout << ans.at(i) << endl;
  }
}
Problem p02618 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  for (int i = 1; i <= 365; i++) {
    cout << rand() % 26 + 1 << endl;
  }
}

Error: TLE

Fixed submission:

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

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

  for (int i = 0; i < 26; i++) {
    cin >> c.at(i).first;
    c.at(i).second = 0;
  }

  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s.at(i).at(j);
    }
  }

  for (int i = 0; i < D; i++) {
    t.at(i) = rand() % 26 + 1;
  }

  int count = 0;
  int S = 0;
  vector<int> ans(D);
  while (count++ < 500000) {

    t.at((rand() % D + 1) - 1) = rand() % 26 + 1;

    int Pl = 0;
    int Mi = 0;

    for (int i = 0; i < D; i++) {
      Pl += s.at(i).at(t.at(i) - 1);
      c.at(t.at(i) - 1).second = i + 1;
      for (int j = 0; j < 26; j++) {
        Mi += c.at(j).first * (i + 1 - c.at(j).second);
      }
      Pl -= Mi;
      Mi = 0;
    }
    if (S < Pl) {
      S = Pl;
      for (int i = 0; i < D; i++) {
        ans.at(i) = t.at(i);
      }
    } else if (S >= Pl) {
      continue;
    }
  }
  for (int i = 0; i < D; i++) {
    cout << ans.at(i) << endl;
  }
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

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

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

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

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

  vector<int> t(D);

  rep(d, D) {
    vector<int>::iterator iter = max_element(s[d].begin(), s[d].end());
    t[d] = distance(s[d].begin(), iter);
    t[d] += 1;
    cout << t[d] << endl;
  }
  /*
    vector<int> last(26);
    vector<int> v(D);

    rep(d, D){
      last[t[d]] = d+1;

      int desc=0;
      rep(i, 26){
        desc += c[i]*(d+1-last[i]);
      }

      if(d==0){
        v[d] = s[d][t[d]] - desc;
      }else{
        v[d] = v[d-1] + s[d][t[d]] - desc;
      }
      cout << v[d] <<endl;
    }
    */
  return 0;
}


Error: -11

Fixed submission:

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

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

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

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

  vector<int> t(D);

  rep(d, D) {
    vector<int>::iterator iter = max_element(s[d].begin(), s[d].end());
    size_t index = distance(s[d].begin(), iter);
    t[d] = s[d][index];
  }

  vector<int> last(26);
  vector<int> v(D);
  int sat = 0;

  rep(d, D) {
    last[t[d]] = d + 1;

    int desc = 0;
    rep(i, 26) { desc += c[i] * (d + 1 - last[i]); }
    // cout <<s[d][t[d]]<<endl;
    // cout << desc << endl;

    if (d == 0) {
      v[d] = s[d][t[d]] - desc;
    } else {
      v[d] = v[d - 1] + s[d][t[d]] - desc;
    }

    cout << v[d] << endl;
  }
  return 0;
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  using namespace chrono_literals;
  chrono::high_resolution_clock clock;
  auto be = clock.now();
  int D;
  cin >> D;
  array<int, 26> c;
  for (auto &e : c)
    cin >> e;
  vector<array<int, 26>> d(D);
  for (auto &r : d)
    for (auto &e : r)
      cin >> e;
  auto eval = [&](vector<int> t) {
    int S = 0;
    array<int, 26> last = {};
    for (int i = 0; i < D; ++i) {
      S += d[i][t[i]];
      last[t[i]] = i + 1;
      for (int j = 0; j < 26; ++j)
        S -= c[j] * (i + 1 - last[j]);
    }
    return S;
  };

  mt19937 mt(random_device{}());
  uniform_int_distribution<int> dist_type(0, 25), dist_day(0, D - 1);
  vector<int> t(D);
  for (int i = 0; i < D; ++i)
    t[i] = distance(cbegin(d[i]), max_element(cbegin(d[i]), cend(d[i]))) + 1;
  int S = eval(t);
  int cnt = 0;
  while (clock.now() - be < 1900ms) {
    int day = dist_day(mt);
    int prv = t[day];
    t[day] = dist_type(mt);
    int score = eval(t);
    if (score > S) {
      S = score;
      continue;
    }
    t[day] = prv;
    if (++cnt > 10000) {
      cnt = 0;
      generate(begin(t), end(t), [&]() { return dist_type(mt); });
    }
  }
  for (const auto &e : t)
    cout << (e + 1) << '\\n';
}


Error: WA

Fixed submission:

// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  using namespace chrono_literals;
  chrono::high_resolution_clock clock;
  auto be = clock.now();
  int D;
  cin >> D;
  array<int, 26> c;
  for (auto &e : c)
    cin >> e;
  vector<array<int, 26>> d(D);
  for (auto &r : d)
    for (auto &e : r)
      cin >> e;
  auto eval = [&](vector<int> t) {
    int S = 0;
    array<int, 26> last = {};
    for (int i = 0; i < D; ++i) {
      S += d[i][t[i]];
      last[t[i]] = i + 1;
      for (int j = 0; j < 26; ++j)
        S -= c[j] * (i + 1 - last[j]);
    }
    return S;
  };

  mt19937 mt(random_device{}());
  uniform_int_distribution<int> dist_type(0, 25), dist_day(0, D - 1);
  vector<int> t(D);
  for (int i = 0; i < D; ++i)
    t[i] = distance(cbegin(d[i]), max_element(cbegin(d[i]), cend(d[i]))) + 1;
  int S = eval(t);
  int cnt = 0;
  while (clock.now() - be < 1900ms) {
    int day = dist_day(mt);
    int prv = t[day];
    t[day] = dist_type(mt);
    int score = eval(t);
    if (score > S) {
      S = score;
      continue;
    }
    t[day] = prv;
    if (++cnt > 10000) {
      cnt = 0;
      generate(begin(t), end(t), [&]() { return dist_type(mt); });
    }
  }
  for (const auto &e : t)
    cout << (e + 1) << '\\n';
  cerr << eval(t);
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int d, c[26][2];

  cin >> d;
  for (int i = 0; i < 26; i++) {
    cin >> c[i][0];
    c[i][1] = 1;
  }

  int s[d][26], d_max[d][2];
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }

  for (int i = 0; i < d; i++) {
    d_max[i][0] = INT_MIN;
    for (int j = 0; j < 26; j++) {
      if (d_max[i][0] < s[i][j] / c[j][1] - d * c[j][0]) {
        d_max[i][0] = s[i][j] / c[j][1] - d * c[j][0];
        d_max[i][1] = j;
      }
    }
    cout << d_max[i][1] + 1 << '\\n';
    c[d_max[i][1]][1]++;
  }

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int d, c[26][2];

  cin >> d;
  for (int i = 0; i < 26; i++) {
    cin >> c[i][0];
    c[i][1] = 1;
  }

  int s[d][26], d_max[d][2];
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }

  for (int i = 0; i < d; i++) {
    d_max[i][0] = INT_MIN;
    for (int j = 0; j < d; j++) {
      if (d_max[i][0] < s[i][j] / c[j][1] - d * c[j][0]) {
        d_max[i][0] = s[i][j] / c[j][1] - d * c[j][0];
        d_max[i][1] = j;
      }
    }
    cout << d_max[i][1] << '\\n';
    c[d_max[i][1]][1]++;
  }

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

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

long long part(vector<int> &C, vector<vector<int>> &S, vector<int> L, int i,
               int j) {
  long long partsum = 0;
  L.at(j) = i + 1;
  partsum += S.at(i).at(j);
  for (int k = 0; k < 26; k++) {
    partsum -= C.at(k) * (i + 1 - L.at(k));
  }
  return partsum;
}

int main() {
  int D;
  cin >> D;
  vector<int> C(26);
  for (int i = 0; i < 26; i++) {
    cin >> C.at(i);
  }
  long long sum = 0;
  vector<vector<int>> S(D, vector<int>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> S.at(i).at(j);
    }
  }
  vector<int> L(26);
  /*スコア関数
  for(int i=0;i<D;i++){
    int T;
    cin >> T;
    L.at(T-1)=i+1;
    sum+=S.at(i).at(T-1);
    for(int j=0;j<26;j++){
      sum-=C.at(j)*(i+1-L.at(j));
    }
    cout << sum << endl;
  }*/
  for (int i = 0; i < D; i++) {
    int tem = 0;
    long long temsum = 0;
    for (int j = 0; j < 26; j++) {
      long long partsum = part(C, S, L, i, j);
      if (partsum > temsum) {
        temsum = partsum;
        tem = j;
      }
    }
    L.at(tem) = i + 1;
    cout << tem + 1 << endl;
  }
}


Error: WA

Fixed submission:

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

int main() {
  int D;
  cin >> D;
  vector<int> C(26);
  for (int i = 0; i < 26; i++) {
    cin >> C.at(i);
  }
  vector<vector<int>> S(D, vector<int>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> S.at(i).at(j);
    }
  }
  vector<int> T;
  int max_score = 0;
  for (int B = 1; B <= D; B++) {
    int max_A = 0;
    for (int k = 1; k < 27; k++) {
      T.push_back(k);
      int score = 0;
      vector<int> memo(26);
      for (int i = 1; i <= B; i++) {
        score += S.at(i - 1).at(T.at(i - 1) - 1);
        memo.at(T.at(i - 1) - 1) = i;
        for (int j = 1; j <= 26; j++) {
          score -= C.at(j - 1) * (i - memo.at(j - 1));
        }
      }
      if (score >= max_score) {
        max_score = score;
        max_A = k;
      }
      T.pop_back();
    }
    T.push_back(max_A);
  }
  for (int i = 0; i < D; i++) {
    cout << T.at(i) << endl;
  }
}
Problem p02618 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

const ll base = 1e6;
int D;
int C[30];
int S[400][30];

ll score(vector<int> &t) {
  vector<int> last(30, 0);
  ll s = 0LL;
  REP(i, D) {
    s += S[i][t[i]];
    last[t[i]] = (i + 1);
    REP(j, 26) { s -= C[j] * (i + 1 - last[j]); }
  }
  return s;
}

void init(vector<int> &t) { REP(i, D) t[i] = (i % 26); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> rand365(0, 364);
  uniform_int_distribution<> rand26(0, 25);

  cin >> D;
  REP(i, 26) cin >> C[i];
  REP(i, D) REP(j, 26) cin >> S[i][j];

  vector<int> T(D);
  // init(T);
  REP(i, D) T[i] = rand26(mt);
  ll max_score = max(base + score(T), 0LL);
  int ti = clock();
  while (clock() - ti < 180 * CLOCKS_PER_SEC / 100) {
    int d = rand365(mt);
    int q = rand26(mt);
    int old = T[d];
    T[d] = q;
    ll tmp = max(base + score(T), 0LL);
    if (max_score < tmp) {
      max_score = tmp;
    } else {
      T[d] = old;
    }
  }
  REP(i, D) cout << T[i] + 1 << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

const ll base = 1e6;
int D;
int C[30];
int S[400][30];

ll score(vector<int> &t) {
  vector<int> last(30, 0);
  ll s = 0LL;
  REP(i, D) {
    s += S[i][t[i]];
    last[t[i]] = (i + 1);
    REP(j, 26) { s -= C[j] * (i + 1 - last[j]); }
  }
  return s;
}

void init(vector<int> &t) { REP(i, D) t[i] = (i % 26); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> rand365(0, 364);
  uniform_int_distribution<> rand26(0, 25);

  cin >> D;
  REP(i, 26) cin >> C[i];
  REP(i, D) REP(j, 26) cin >> S[i][j];

  vector<int> T(D);
  // init(T);
  REP(i, D) T[i] = rand26(mt);
  ll max_score = max(base + score(T), 0LL);
  int ti = clock();
  while (clock() - ti < 199 * CLOCKS_PER_SEC / 100) { // 2.99秒で打ち切り
    vector<int> t_cp = T;
    int d = rand365(mt);
    int q = rand26(mt);
    t_cp[d] = q;
    ll tmp = max(base + score(t_cp), 0LL);
    if (max_score < tmp) {
      max_score = tmp;
      T[d] = q;
    }
  }
  REP(i, D) cout << T[i] + 1 << '\\n';
  return 0;
}
Problem p02618 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<Int, Int> P;

Int D;
vector<Int> C(26);
vector<vector<Int>> S(365, vector<Int>(26));

// 最終的な満足度を返す関数
Int score(vector<int> schedule) {
  vector<int> last_day(26, 0); // 各コンテストを最後に行った日

  vector<Int> res(D, 0);

  rep(d, D) {
    int type = schedule[d] - 1; // その日に行われるコンテスト

    res[d] += S[d][type];
    rep(i, 26) {
      if (i == type)
        continue;
      res[d] -= C[i] * (d + 1 - last_day[i]);
    }
    last_day[type] = d + 1;

    if (d != D - 1)
      res[d + 1] += res[d];
  }

  return res[D - 1];
}

int main() {
  clock_t start = clock();

  cin >> D;
  rep(i, 26) cin >> C[i];
  rep(i, D) rep(j, 26) cin >> S[i][j];

  vector<int> t_old(D);
  rep(i, D) t_old[i] = (i % 26) + 1;

  int old_score = score(t_old);

  rep(k, 10000) {
    vector<int> t_new = t_old;
    int d = rand() % D, q = rand() % 26 + 1;
    // cout << d << " " << q << endl;
    t_new[d] = q;

    if (score(t_new) > old_score)
      t_old = t_new;
  }

  rep(i, D) cout << t_old[i] << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<Int, Int> P;

Int D;
vector<Int> C(26);
vector<vector<Int>> S(365, vector<Int>(26));

// 最終的な満足度を返す関数
Int score(vector<int> schedule) {
  vector<int> last_day(26, 0); // 各コンテストを最後に行った日

  vector<Int> res(D, 0);

  rep(d, D) {
    int type = schedule[d] - 1; // その日に行われるコンテスト

    res[d] += S[d][type];
    rep(i, 26) {
      if (i == type)
        continue;
      res[d] -= C[i] * (d + 1 - last_day[i]);
    }
    last_day[type] = d + 1;

    if (d != D - 1)
      res[d + 1] += res[d];
  }

  return res[D - 1];
}

int main() {
  clock_t start = clock();

  cin >> D;
  rep(i, 26) cin >> C[i];
  rep(i, D) rep(j, 26) cin >> S[i][j];

  vector<int> t_old(D);
  rep(i, D) t_old[i] = (i % 26) + 1;

  int old_score = score(t_old);

  rep(k, 1000000) {
    vector<int> t_new = t_old;
    int d = rand() % D, q = rand() % 26 + 1;
    // cout << d << " " << q << endl;
    t_new[d] = q;

    if (score(t_new) > old_score)
      t_old = t_new;
  }

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

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

int main() {
  int d;

  cin >> d;

  vector<int> c(26, 0);
  vector<vector<int>> s(d, vector<int>(26, 0));
  vector<int> last(26, 0);

  vector<int> ans(d, 0);

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

  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }

  int max;
  int k;
  for (int i = 0; i < d; i++) {
    max = s[i][0] + c[0] * (i + 1 - last[0]);
    k = 0;
    for (int j = 1; j < 26; j++) {
      int p = s[i][j] + c[j] * (i + 1 - last[j]);
      if (max < p) {
        max = p;
        k = j;
      } else if (max == p) {
        if (c[k] < c[j]) {
          max = p;
          k = j;
        }
      }
    }
    ans[i] = k;
    last[k]++;
  }

  for (int i = 0; i < d; i++) {
    cout << ans[i] + 1 << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int d;

  cin >> d;

  vector<int> c(26, 0);
  vector<vector<int>> s(d, vector<int>(26, 0));
  vector<int> last(26, 0);

  vector<int> ans(d, 0);

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

  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }

  int max;
  int k;
  for (int i = 0; i < d; i++) {
    max = -1;
    k = -1;
    for (int j = 0; j < 26; j++) {
      int p = s[i][j] + c[i] * (i + 1 - last[j]);
      if (max < p) {
        max = p;
        k = j;
      } else if (max == p) {
        if (c[k] < c[j]) {
          max = p;
          k = j;
        }
      }
    }
    ans[i] = k;
    last[k]++;
  }

  for (int i = 0; i < d; i++) {
    cout << ans[i] + 1 << endl;
  }

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

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

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

int cal_score(vector<int> t) {
  vector<int> res(D);
  int satis = 0;
  vector<int> last(26, 0);
  rep(d, D) {
    satis += s[d][t[d] - 1];
    last[t[d] - 1] = d + 1;
    rep(i, 26) { satis -= c[i] * (d - last[i] + 1); }
    res[d] = satis;
  }
  return res[D - 1];
}

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

  // greedy
  vector<int> last(26, 0);
  vector<int> res(D);

  rep(d, D) {
    int max_plus = -10000;
    int use = -1;
    rep(i, 26) {
      int tmp = s[d][i] + c[i] * (d - last[i] + 1);
      if (max_plus < tmp) {
        max_plus = tmp;
        use = i;
      }
    }
    last[use] = d + 1;
    res[d] = use + 1;
  }

  int cur_score = cal_score(res);

  while ((clock() / (double)CLOCKS_PER_SEC) < 1.5) {
    int ch_d = rand() % D + 1;
    int ch_c = rand() % 26 + 1;
    int old_c = res[ch_d - 1];
    res[ch_d - 1] = ch_c;
    int new_score = cal_score(res);
    if (cur_score < new_score) {
      cur_score = new_score;
    } else {
      res[ch_d - 1] = old_c;
    }
  }

  rep(i, D) { cout << res[i] << endl; }
  return 0;
}

Error: TLE

Fixed submission:

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

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

int cal_score(vector<int> t) {
  vector<int> res(D);
  int satis = 0;
  vector<int> last(26, 0);
  rep(d, D) {
    satis += s[d][t[d] - 1];
    last[t[d] - 1] = d + 1;
    rep(i, 26) { satis -= c[i] * (d - last[i] + 1); }
    res[d] = satis;
  }
  return res[D - 1];
}

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

  // greedy
  vector<int> last(26, 0);
  vector<int> res(D);

  rep(d, D) {
    int max_plus = -10000;
    int use = -1;
    rep(i, 26) {
      int tmp = s[d][i] + c[i] * (d - last[i] + 1);
      if (max_plus < tmp) {
        max_plus = tmp;
        use = i;
      }
    }
    last[use] = d + 1;
    res[d] = use + 1;
  }

  int cur_score = cal_score(res);

  while (clock() / CLOCKS_PER_SEC <= 1.5) {
    int ch_d = rand() % D + 1;
    int ch_c = rand() % 26 + 1;
    int old_c = res[ch_d - 1];
    res[ch_d - 1] = ch_c;
    int new_score = cal_score(res);
    if (cur_score < new_score) {
      cur_score = new_score;
    } else {
      res[ch_d - 1] = old_c;
    }
  }

  rep(i, D) { cout << res[i] << endl; }
  return 0;
}