Language: C++

/**
*    author:  boutarou
*    created: 28.06.2020 20:54:48
**/

#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

const double PI = 3.1415926535897932;
const int INF = 1e9;

int d;
int c[26];
int s[365][26];
vector<int> previous(26);

int score(int day, int contest, vector<int> before) {
    int cnt = 0;
    cnt += s[day][contest];
    before[contest] = day;
    rep(i, 26) {
        cnt -= c[i] * (day - before[i]);
    }
    return cnt;
}

int score2(int day, int contest1, int contest2, vector<int> before) {
    int cnt = 0;
    cnt += s[day][contest1];
    before[contest1] = day;
    rep(i, 26) {
        cnt -= c[i] * (day - before[i]);
    }
    day++;
    cnt += s[day][contest2];
    before[contest2] = day;
    rep(i, 26) {
        cnt -= c[i] * (day - before[i]);
    }
    return cnt;
}

int score3(int day, int contest1, int contest2, int contest3, vector<int> before) {
    int cnt = 0;
    cnt += s[day][contest1];
    before[contest1] = day;
    rep(i, 26) {
        cnt -= c[i] * (day - before[i]);
    }
    day++;
    cnt += s[day][contest2];
    before[contest2] = day;
    rep(i, 26) {
        cnt -= c[i] * (day - before[i]);
    }
    day++;
    cnt += s[day][contest3];
    before[contest3] = day;
    rep(i, 26) {
        cnt -= c[i] * (day - before[i]);
    }
    return cnt;
}

int score4(int day, int contest1, int contest2, int contest3, int contest4, vector<int> before) {
    int cnt = 0;
    cnt += s[day][contest1];
    before[contest1] = day;
    rep(i, 26) {
        cnt -= c[i] * (day - before[i]);
    }
    day++;
    cnt += s[day][contest2];
    before[contest2] = day;
    rep(i, 26) {
        cnt -= c[i] * (day - before[i]);
    }
    day++;
    cnt += s[day][contest3];
    before[contest3] = day;
    rep(i, 26) {
        cnt -= c[i] * (day - before[i]);
    }
    day++;
    cnt += s[day][contest4];
    before[contest4] = day;
    rep(i, 26) {
        cnt -= c[i] * (day - before[i]);
    }
    return cnt;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> d;
    rep(i, 26) cin >> c[i];
    rep(i, d) {
        rep(j, 26) cin >> s[i][j];
    }

    rep(i, 26) previous[i] = -1;

    int now = 0;
    for (int i = 0; i + 3 < d; i += 4) {
        int ma = -INF;
        rep(j, 26) {
            rep(k, 26) {
                rep(l, 26) {
                    rep(m, 26) {
                        ma = max(ma, score4(i, j, k, l, m, previous));
                    }
                }
            }
        }
        rep(j, 26) {
            rep(k, 26) {
                rep(l, 26) {
                    rep(m, 26) {
                        if (ma == score4(i, j, k, l, m, previous)) {
                            cout << j + 1 << endl;
                            cout << k + 1 << endl;
                            cout << l + 1 << endl;
                            cout << m + 1 << endl;
                            now += score4(i, j, k, l, m, previous);
                            previous[j] = i;
                            previous[k] = i + 1;
                            previous[l] = i + 2;
                            previous[m] = i + 3;
                            goto bou;
                        }
                    }
                }
            }
        }
        bou:;
    }
    if (d % 4 == 1) {
        int i = d - 1;
        int ma = -INF;
        rep(j, 26) {
            ma = max(ma, score(i, j, previous));
        }
        rep(j, 26) {
            if (ma == score(i, j, previous)) {
                cout << j + 1 << endl;
                now += score(i, j, previous);
                previous[j] = i;
                break;
            }
        }
    }
    
    return 0;
}


Compiler output:
In file included from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:10:
/usr/include/c++/14/bits/allocator.h: In destructor 'std::_Vector_base<int, std::allocator<int> >::_Vector_impl::~_Vector_impl()':
/usr/include/c++/14/bits/allocator.h:182:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = int]': target specific option mismatch
  182 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:132:14: note: called from here
  132 |       struct _Vector_impl
      |              ^~~~~~~~~~~~