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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
  int D; // 365
  cin >> D;
  int c[26];
  rep(i, 0, 26) { cin >> c[i]; }
  int s[D][26];
  rep(i, 0, D) {
    rep(j, 0, 26) { cin >> s[i][j]; }
  }
  int t[D];
  rep(i, 0, D) {
    cin >> t[i];
    t[i]--;
  }
  ll score[D] = {};
  rep(i, 0, D) score[i] = 1;
  /*vector<int> last_day(26, -1);
  rep(i, 0, D) {
      if (i != 0) score[i] = score[i - 1];
      score[i] += s[i][t[i]];
      last_day[t[i]] = i;
      int decrease = 0;
      rep(j, 0, 26) {
          decrease += c[j] * (i - last_day[j]);
      }
      score[i] -= decrease;
  }*/
  rep(i, 0, D) { cout << score[i] << endl; }
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
  int D; // 365
  cin >> D;
  int c[26];
  rep(i, 0, 26) { cin >> c[i]; }
  int s[D][26];
  rep(i, 0, D) {
    rep(j, 0, 26) { cin >> s[i][j]; }
  }
  int t[D];
  rep(i, 0, D) {
    cin >> t[i];
    t[i]--;
  }
  ll score = 0;
  vector<int> last_day(26, -1);
  rep(i, 0, D) {
    score += s[i][t[i]];
    last_day[t[i]] = i;
    int decrease = 0;
    rep(i, 0, 26) { decrease += c[t[i]] * (i - last_day[t[i]]); }
    score -= decrease;
    cout << score << endl;
  }
  return 0;
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

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

/*==============変数宣言==============*/
int N;
const int M = 26;
int n;
int m = M;

int c[30];
int s[400][30];

void input() {
  scanf("%d", &N);
  n = N;

  for (int i = 0; i < M; i++)
    scanf("%d", &c[i]);

  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++)
      scanf("%d", &s[i][j]);

  return;
}

/*================乱数================*/
/*====================================*/

void init() {
  input();
  return;
}

void output(int ans[]) {
  for (int i = 0; i < n; i++) {
    printf("%d\\n", ans[i] + 1);
  }
}

int main() {
  init();

  int ans[500];

  for (int i = 0; i < n; i++) {
    ans[i] = i % 26;
  }

  output(ans);

  return 0;
}

Error: WA

Fixed submission:

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

/*==============変数宣言==============*/
int N;
const int M = 26;
int n;
int m = M;

int c[30];
int s[400][30];

void input() {
  scanf("%d", &N);
  n = N;

  for (int i = 0; i < M; i++)
    scanf("%d", &c[i]);

  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++)
      scanf("%d", &s[i][j]);

  return;
}

/*================乱数================*/
/*====================================*/

int init() { input(); }

void output(int ans[]) {
  for (int i = 0; i < n; i++) {
    printf("%d\\n", ans[i] + 1);
  }
}

int main() {
  init();

  int ans[500];

  for (int i = 0; i < n; i++) {
    ans[i] = i % 26;
  }

  output(ans);

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

#include <iostream>
#include <vector>
using namespace std;

int main() {

  /*---------*/
  /*  input  */
  /*---------*/

  int D;
  cin >> D;

  int i, j;
  vector<int> c(26 + 1);
  for (i = 1; i <= 26; i++) {
    cin >> c[i];
  }

  vector<vector<int>> s(D + 1, vector<int>(26 + 1));
  for (i = 1; i <= D; i++) {
    for (j = 1; j <= 26; j++) {
      cin >> s[i][j];
    }
  }

  /*
      vector<int> t(365+1);
      for( i = 1; i <= D; i++ ){
          cin >> t[i];
      }
  */

  /*--------*/
  /*  calc  */
  /*--------*/

  long long int p = 0;
  int m = 0;
  int d; // d: 1 --> D(365)
  vector<int> last(26 + 1);
  vector<int> real_last(26 + 1);
  long long int total = 0;
  long long int score;
  long long int ans = -10000000000;
  int x, k, tmp;

  for (d = 1; d <= D; d++) {

    // ans = -100000000000;

    for (i = 1; i <= 26; i++) {
      for (k = 1; k <= 26; k++)
        last[k] = real_last[k];
      p = s[d][i];
      // minus
      // m = 0;
      // last[]を更新
      // tmp = last[i];  // 記憶
      last[i] = d;
      if (i == 1) {
        m = 0;
        for (j = 1; j <= 26; j++) {
          m += c[j] * (d - last[j]);
        }
        ans = p - m;
        x = 1;
      } else {
        m = m + c[i - 1] * (d - last[i - 1]) - c[i] * (d - tmp);
        score = p - m;
        if (score > ans) {
          x = i;
          ans = score;
        }
        // else last[i] = tmp;
      }
    }
    // real_last[]を更新
    real_last[x] = d;
    cout << x << endl;
  }
}


Error: -11

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {

  /*---------*/
  /*  input  */
  /*---------*/

  int D;
  cin >> D;

  int i, j;
  vector<int> c(26 + 1);
  for (i = 1; i <= 26; i++) {
    cin >> c[i];
  }

  vector<vector<int>> s(D + 1, vector<int>(26 + 1));
  for (i = 1; i <= D; i++) {
    for (j = 1; j <= 26; j++) {
      cin >> s[i][j];
    }
  }

  /*
      vector<int> t(365+1);
      for( i = 1; i <= D; i++ ){
          cin >> t[i];
      }
  */

  /*--------*/
  /*  calc  */
  /*--------*/

  long long int p = 0;
  int m = 0;
  int d; // d: 1 --> D(365)
  vector<int> last(26 + 1);
  vector<int> real_last(26 + 1);
  long long int total = 0;
  long long int score;
  long long int ans = -10000000000;
  int x, k, tmp;

  for (d = 1; d <= D; d++) {

    // ans = -100000000000;

    for (i = 1; i <= 26; i++) {
      // for( k = 1; k <= 26; k++ ) last[k] = real_last[k];
      p = s[d][i];
      // minus
      // m = 0;
      // last[]を更新
      tmp = last[i]; // 記憶
      last[i] = d;
      if (i == 1) {
        m = 0;
        for (j = 1; j <= 26; j++) {
          m += c[j] * (d - last[j]);
        }
        ans = p - m;
      } else {
        m = m + c[i - 1] * (d - last[i - 1]) - c[i] * (d - tmp);
      }
      score = p - m;
      if (score > ans) {
        x = i;
        ans = score;
      } else
        last[i] = tmp;
    }
    // real_last[]を更新
    real_last[x] = d;
    cout << x << endl;
  }
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int64_t min(int64_t a, int64_t b) {
  if (a > b) {
    return b;
  } else {
    return a;
  }
}

int main() {
  int d;
  cin >> d;
  vector<int> c(26, 0);
  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> ans(0);
  vector<int64_t> score(0);
  int64_t snow = 0;
  vector<int> last(26, -1);
  vector<int> judge(26, 0);
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      judge.at(j) = c.at(j) * (i - last.at(j)) + s.at(i).at(j);
    }

    int num = 1;
    int temp = judge.at(0);
    for (int j = 0; j < 26; j++) {
      if (temp < judge.at(j)) {
        temp = s.at(i).at(j);
        num = j + 1;
      }
    }
    ans.push_back(num);
    // snow += s.at(i).at(num-1) ;
    last.at(num - 1) = i;
    for (int j = 0; j < 26; j++) {
      snow -= c.at(j) * (i - last.at(j));
    }
    // score.push_back(snow) ;
  }
  for (int i = 0; i < d; i++) {
    cout << ans.at(i) << endl;
  }
  // cout << snow << endl ;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int64_t min(int64_t a, int64_t b) {
  if (a > b) {
    return b;
  } else {
    return a;
  }
}

int main() {
  int d;
  cin >> d;
  vector<int> c(26, 0);
  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> ans(0);
  vector<int64_t> score(0);
  int64_t snow = 0;
  vector<int> last(26, -1);
  vector<int> judge(26, 0);
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      judge.at(j) = c.at(i) * (i - last.at(j)) + s.at(i).at(j);
    }

    int num = 1;
    int temp = judge.at(0);
    for (int j = 0; j < 26; j++) {
      if (temp < judge.at(j)) {
        temp = s.at(i).at(j);
        num = j + 1;
      }
    }
    ans.push_back(num);
    snow += s.at(i).at(num - 1);
    last.at(num - 1) = i;
    for (int j = 0; j < 26; j++) {
      snow -= c.at(j) * (i - last.at(j));
    }
    score.push_back(snow);
  }
  for (int i = 0; i < d; i++) {
    cout << ans.at(i) << endl;
  }
  // cout << snow << endl ;
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <climits>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

vector<int> cs;
vector<vector<int>> sm;

int total_satisfaction(vector<int> &ts, int d) {
  vector<int> ls;
  for (int i = 0; i < 26; i++)
    ls.push_back(0);
  int s = 0;

  for (int i = 0; i < d; i++) {
    int t = ts[i];
    t--;
    s += sm[i][t];
    ls[t] = i + 1;

    int dis = 0;
    for (int j = 0; j < 26; j++) {
      dis += cs[j] * ((i + 1) - ls[j]);
    }
    s -= dis;
  }

  return s;
}

int main() {
  int d;
  vector<int> ts;

  cin >> d;

  int x;
  for (int i = 0; i < 26; i++) {
    cin >> x;
    cs.push_back(x);
  }
  for (int i = 0; i < d; i++) {
    vector<int> v;
    sm.push_back(v);
    for (int j = 0; j < 26; j++) {
      cin >> x;
      sm[i].push_back(x);
    }
  }

  for (int i = 0; i < d; i++) {
    int mx = INT_MIN;
    int mxt = -1;

    for (int t = 1; t <= 26; t++) {
      ts.push_back(t);
      int s = total_satisfaction(ts, i + 1);
      if (s > mx) {
        mx = s;
        mxt = t;
      }
      ts.pop_back();
    }

    ts.push_back(mxt);
    cout << mxt << endl;
  }
}


Error: WA

Fixed submission:

#include <climits>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

vector<int> cs;
vector<vector<int>> sm;

int total_satisfaction(vector<int> &ts, int d) {
  vector<int> ls;
  for (int i = 0; i < 26; i++)
    ls.push_back(0);
  int s = 0;

  for (int i = 0; i < d; i++) {
    int t = ts[i];
    t--;
    s += sm[i][t];
    ls[t] = i + 1;

    int dis = 0;
    for (int j = 0; j < 26; j++) {
      dis += cs[j] * ((i + 1) - ls[j]);
    }
    s -= dis;
  }

  return s;
}

int main() {
  int d;
  vector<int> ts;

  cin >> d;

  int x;
  for (int i = 0; i < 26; i++) {
    cin >> x;
    cs.push_back(x);
  }
  for (int i = 0; i < d; i++) {
    vector<int> v;
    sm.push_back(v);
    for (int j = 0; j < 26; j++) {
      cin >> x;
      sm[i].push_back(x);
    }
  }

  for (int i = 0; i < d; i++) {
    int mx = INT_MIN;
    int mxt = -1;

    for (int t = 1; t <= d; t++) {
      ts.push_back(t);
      int s = total_satisfaction(ts, i + 1);
      if (s > mx) {
        mx = s;
        mxt = t;
      }
      ts.pop_back();
    }

    ts.push_back(mxt);
    cout << mxt << endl;
  }
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll; // int:2*10**9
typedef long double ld;
typedef pair<ll, ll> P;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define vec2(name, i, j, k) vector<vector<ll>> name(i, vector<ll>(j, k))
#define vec3(name, i, j, k, l)                                                 \\
  vector<vector<vector<ll>>> name(i, vector<vector<ll>>(j, vector<ll>(k, l)))
#define pb push_back
#define MOD 1000000007 // 998244353
#define PI 3.141592653
#define INF 100000000000000 // 14
// cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
int main() {
  ll d, t;
  cin >> d;
  vector<ll> ansl(365, -1);
  vector<ll> c(26);
  vector<ll> las(26, 0);
  vec2(s, d, 26, 0);
  REP(i, 26) cin >> c[i];
  REP(i, d) REP(j, 26) cin >> s[i][j];
  ll con = 0;
  FOR(i, 1, d) {
    ll max = -1 * INF;
    ll mind = -1;
    REP(j, 26) if (max < s[i - 1][j]) {
      max = s[i - 1][j];
      con -= c[j] * (i - las[j]);
      mind = j;
    }
    ansl[i - 1] = mind;
    con += c[mind] * (i - las[mind]);
    las[mind] = i;
  }

  REP(i, d) cout << ansl[i] + 1 << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll; // int:2*10**9
typedef long double ld;
typedef pair<ll, ll> P;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define vec2(name, i, j, k) vector<vector<ll>> name(i, vector<ll>(j, k))
#define vec3(name, i, j, k, l)                                                 \\
  vector<vector<vector<ll>>> name(i, vector<vector<ll>>(j, vector<ll>(k, l)))
#define pb push_back
#define MOD 1000000007 // 998244353
#define PI 3.141592653
#define INF 100000000000000 // 14
// cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
int main() {
  ll d, t;
  cin >> d;
  vector<ll> ansl(26, -1);
  vector<ll> c(26);
  vector<ll> las(26, 0);
  vec2(s, d, 26, 0);
  REP(i, 26) cin >> c[i];
  REP(i, d) REP(j, 26) cin >> s[i][j];
  ll con = 0;
  FOR(i, 1, d) {
    ll max = -1 * INF;
    ll mind = -1;
    REP(j, 26) if (max < s[i - 1][j]) {
      max = s[i - 1][j];
      con -= c[j] * (i - las[j]);
      mind = j;
    }
    ansl[i - 1] = mind;
    con += c[mind] * (i - las[mind]);
    las[mind] = i;
  }
  REP(i, d) cout << ansl[i] + 1 << endl;
}
Problem p02618 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

struct abc {
  int id;
  int last = 0;
  int c;
  vi s;

public:
  abc(int n, int id) {
    s = vi(n + 1);
    this->id = id;
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int d;
  cin >> d;
  vector<abc> abcs;
  rep(i, 26) abcs.push_back(abc(d, i + 1));

  rep(i, 26) { cin >> abcs[i].c; }

  rep(i, d) { rep(j, 26) cin >> abcs[j].s[i + 1]; }

  vi ret(d);

  for (int day = 1; day <= d; day++) {
    sort(all(abcs), [=](auto const &lhs, auto const &rhs) {
      return lhs.c * (day - lhs.last) + lhs.s[day] >
             rhs.c * (day - rhs.last) + rhs.s[day];
    });

    ret[day - 1] = abcs[0].id;
    abcs[0].last = day;
  }

  rep(i, d) { cout << ret[i] << endl; }
}

Error: WA

Fixed submission:

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

struct abc {
  int id;
  int last = 0;
  int c;
  vi s;

public:
  abc(int n, int id) {
    s = vi(n);
    this->id = id;
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int d;
  cin >> d;
  vector<abc> abcs;
  rep(i, 26) abcs.push_back(abc(26, i + 1));

  rep(i, 26) { cin >> abcs[i].c; }

  rep(i, d) { rep(j, 26) cin >> abcs[j].s[i]; }

  vi ret(26);

  for (int day = 1; day <= d; day++) {
    sort(all(abcs), [=](auto const &lhs, auto const &rhs) {
      return lhs.c * (day - lhs.last) + lhs.s[day] >
             rhs.c * (day - rhs.last) + rhs.s[day];
    });

    ret[day - 1] = abcs[0].id;
    abcs[0].last = day;
  }

  rep(i, d) { cout << ret[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;
using ll = long long;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int D;
vector<int> c(26 + 1);
vector<vector<int>> s;

int compute_score(vector<int> t) {
  vector<vector<int>> last(D + 1, vector<int>(26 + 1, 0));
  int ans = 0;
  for (int d = 1; d <= D; d++) {
    last[d][t[d]] = d;
    ans += s[d][t[d]];
    for (int i = 1; i <= 26; i++) {
      if (i == t[d])
        continue;
      last[d][i] = last[d - 1][i];
      ans -= c[i] * (d - last[d][i]);
    }
  }
  return 0;
}

vector<int> greedy() {
  vector<int> t(D + 1);
  vector<vector<int>> last(D + 1, vector<int>(26 + 1, 0));
  for (int d = 1; d <= D; d++) {
    int best_i;
    int best_score_diff = -INT32_MAX;
    for (int i = 1; i <= 26; i++) {
      int score_diff = s[d][i] - c[i] * (d - last[d][i]);
      if (score_diff >= best_score_diff) {
        best_i = i;
        best_score_diff = score_diff;
      }
    }
    for (int i = 1; i <= 26; i++) {
      if (i == best_i) {
        last[d][i] = d;
        t[d] = i;
      } else {
        last[d][i] = last[d - 1][i];
      }
    }
  }
  return t;
}

int main() {
  ios::sync_with_stdio(false);
  cin >> D;
  s.assign(D + 1, vector<int>(26 + 1, 0));
  for (int i = 1; i <= 26; i++)
    cin >> c[i];
  for (int d = 1; d <= D; d++)
    for (int i = 1; i <= 26; i++)
      cin >> s[d][i];

  vector<int> t = greedy();
  for (int d = 1; d <= D; d++)
    cout << t[d] << endl;
}


Error: WA

Fixed submission:

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

int D;
vector<int> c(26 + 1);
vector<vector<int>> s;

int compute_score(vector<int> t) {
  vector<vector<int>> last(D + 1, vector<int>(26 + 1, 0));
  int ans = 0;
  for (int d = 1; d <= D; d++) {
    last[d][t[d]] = d;
    ans += s[d][t[d]];
    for (int i = 1; i <= 26; i++) {
      if (i == t[d])
        continue;
      last[d][i] = last[d - 1][i];
      ans -= c[i] * (d - last[d][i]);
    }
    cout << ans << endl;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin >> D;
  s.assign(D + 1, vector<int>(26 + 1, 0));
  for (int i = 1; i <= 26; i++)
    cin >> c[i];
  for (int d = 1; d <= D; d++)
    for (int i = 1; i <= 26; i++)
      cin >> s[d][i];
  vector<int> t(D + 1);
  for (int d = 1; d <= D; d++)
    cin >> t[d];
  compute_score(t);
}
Problem p02618 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
#define INF 1e9

static const int seed = 6;
static const int D = 365;
static const int ntype = 26;
static int ans[D + 1];
static int max_score = -INF;
static int t = 1e4;
class Contest {
public:
  Contest() { last = 0; }
  int s[D + 1];
  int c;
  int last;
};

static Contest contest[ntype + 1];

void Input() {
  int d;
  cin >> d;
  for (int i = 1; i <= ntype; ++i) {
    int t;
    cin >> t;
    contest[i].c = t;
  }
  for (int day = 1; day <= D; ++day) {
    for (int type = 1; type <= ntype; ++type) {
      int t;
      cin >> t;
      contest[type].s[day] = t;
    }
  }
}

int evaluate() {
  int sum = 0;
  vector<int> l(ntype + 1, 0);
  for (int day = 1; day <= D; ++day) {
    int type = ans[day];
    sum += contest[type].s[day];
    l[type] = day;
    for (int t = 1; t <= ntype; ++t) {
      sum -= contest[t].c * (day - l[t]);
    }
  }
  return sum;
}

void Output() {
  for (int d = 1; d <= D; ++d)
    cout << ans[d] << endl;
}

void Init() {
  for (int d = 1; d <= D; ++d)
    ans[d] = rand() % ntype + 1;
}

void solve(int time) {
  max_score = evaluate();
  for (int i = 0; i < time; ++i) {
    int p = rand() % D + 1;
    int temp = ans[p];
    ans[p] = rand() % ntype + 1;
    int temp_score = evaluate();
    if (max_score < temp_score)
      max_score = temp_score;
    else
      ans[p] = temp;
  }
}

int main() {
  srand(seed);
  Input();
  Init();
  solve(t);
  Output();
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
#define INF 1e9

static const int seed = 6;
static const int D = 365;
static const int ntype = 26;
static int ans[D + 1];
static int max_score = -INF;
static int t = 1e6;
class Contest {
public:
  Contest() { last = 0; }
  int s[D + 1];
  int c;
  int last;
};

static Contest contest[ntype + 1];

void Input() {
  int d;
  cin >> d;
  for (int i = 1; i <= ntype; ++i) {
    int t;
    cin >> t;
    contest[i].c = t;
  }
  for (int day = 1; day <= D; ++day) {
    for (int type = 1; type <= ntype; ++type) {
      int t;
      cin >> t;
      contest[type].s[day] = t;
    }
  }
}

int evaluate() {
  int sum = 0;
  vector<int> l(ntype + 1, 0);
  for (int day = 1; day <= D; ++day) {
    int type = ans[day];
    sum += contest[type].s[day];
    l[type] = day;
    for (int t = 1; t <= ntype; ++t) {
      sum -= contest[t].c * (day - l[t]);
    }
  }
  return sum;
}

void Output() {
  for (int d = 1; d <= D; ++d)
    cout << ans[d] << endl;
}

void Init() {
  for (int d = 1; d <= D; ++d)
    ans[d] = rand() % ntype + 1;
}

void solve(int time) {
  max_score = evaluate();
  for (int i = 0; i < time; ++i) {
    int p = rand() % D + 1;
    int temp = ans[p];
    ans[p] = rand() % ntype + 1;
    int temp_score = evaluate();
    if (max_score < temp_score)
      max_score = temp_score;
    else
      ans[p] = temp;
  }
}

int main() {
  srand(seed);
  Input();
  Init();
  solve(t);
  Output();
}