Language: C++

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

template<typename T>
inline bool chmax(T& x, T a) {
	if (x <= a) { x = a; return true; }
	return false;
}

#define INITIAL_SAMPLE_NUM 10
#define ANNEALING_ITERATION_NUM 2000
#define ANNEALING_SEARCH_NUM 10

#define INF (1LL << 60)

unsigned int SEED() {
	random_device rd;
	return rd();
}
mt19937_64 MT(SEED());
ll rand(ll a, ll b) {// [a, b]から乱数生成
	uniform_int_distribution<ll> dis(a, b);
	return dis(MT);
}

template<typename T_score, typename T_ans> T_ans generate(double param); // ランダムに初期値を生成する関数
template<typename T_ans> T_ans change(T_ans &params); // パラメータの一部を変える関数
template<typename T_score, typename T_ans> T_score calc(T_ans &params); // パラメータをもとにスコアを計算する

template<typename T_score, typename T_ans> T_score getDiffScale(int N = 20) {// 標準偏差を計算する
	T_score sum = 0;
	vector<T_score> v(N);
	for (int i = 0; i < N; i++) {
		T_ans g = generate<T_score, T_ans>();
		T_score a = calc<T_score, T_ans>(g);
		sum += a;
		v[i] = a;
	}
	sum /= N;
	for (int i = 0; i < N; i++) {
		v[i] -= sum;
	}
	T_score ans = 0;
	for (int i = 0; i < N; i++) {
		ans += v[i] * v[i];
	}
	return sqrt(ans);
}
template<typename T_score, typename T_ans> pair<T_score, T_ans> annealing(T_ans &initParams, T_score scale, int N) { // 焼きなまし法
	T_ans tempParams = initParams;
	T_score s0 = calc<T_score, T_ans>(tempParams);
	for (int iteration = N; iteration > 0; iteration--) {
		vector<T_ans> v(ANNEALING_SEARCH_NUM);
		vector<T_score> s(ANNEALING_SEARCH_NUM);
		for (int i = 0; i < ANNEALING_SEARCH_NUM; i++) {
			v[i] = change(tempParams);
			s[i] = calc<T_score, T_ans>(v[i]);
		}
		int k = 0;
		T_score smax = s[0];
		for (int i = 1; i < ANNEALING_SEARCH_NUM; i++) {
			if (s[i] > smax) {
				k = i; smax = s[i];
			}
		}
		if (smax > s0) {
			s0 = smax;
			tempParams = v[k];
		}
		else {
			double p = (double)(s0 - smax) / (double)scale;
			p *= (double)N / (double)iteration;
			if (p < 1) {
				p = 1 - p;
				p *= p;
				if ((double)rand(0, INF) < (double)INF * p) {
					s0 = smax;
					tempParams = v[k];
				}
			}
		}
	}
	return make_pair(s0, tempParams);
}
template<typename T_score, typename T_ans> pair<T_score, T_ans> optimize(T_ans &initParams) { // 初期パラメータを変化させて最適値に持っていく
	T_score scale = getDiffScale<T_score, T_ans>();
	return annealing<T_score, T_ans>(initParams, scale, ANNEALING_ITERATION_NUM);
}
template<typename T_score, typename T_ans>
inline pair<T_score, T_ans> argmax(int N) {// N個の初期値に対して最もスコアが高かったものを選択
	T_ans g0 = generate<T_score, T_ans>();
	pair<T_score, T_ans> p0 = optimize<T_score, T_ans>(g0);
	for (int i = 1; i < N; i++) {
		T_ans g = generate<T_score, T_ans>();
		pair<T_score, T_ans> p = optimize<T_score, T_ans>(g);
		if (p.first > p0.first) {
			p0 = p;
		}
	}
	return p0;
}

int D;
constexpr int M = 26;
vector<ll> C(M);
vector<vector<ll>> S;

template<typename T_score, typename T_ans> T_ans generate(double param = 0.9) { // ランダムに初期値を生成する
	vector<ll> last(26, 0);
	vector<ll> v(D);

	ll score = 0;
	for (int i = 0; i < D; i++) {
		if (rand(0, INF) < INF * param) {// 貪欲
			vector<T_score> s(M);
			for (int j = 0; j < M; j++) {
				s[j] = S[i][j] + C[j] * (i + 1 - last[j]);
			}

			int k = 0;
			T_score s0 = s[0];
			for (int j = 1; j < M; j++) {
				if (s0 < s[j]) {
					k = j;
				}
			}
			v[i] = k;
		}
		else {
			v[i] = rand(0, M - 1);
		}
	}

	return v;
}
template<typename T_ans> T_ans change(T_ans &params) { // パラメータの一部を変える
	int k = rand(0, D - 1);
	T_ans v(D);
	for (int i = 0; i < D; i++) {
		v[i] = params[i];
	}
	v[k] = rand(0, M - 1);
	return v;
}
template<typename T_score, typename T_ans> T_score calc(T_ans &params) { // パラメータをもとにスコアを計算する
	vector<ll> last(26, 0);
	ll score = 0;
	for (int i = 0; i < D; i++) {
		score += S[i][params[i]];
		last[params[i]] = i + 1;
		for (int j = 0; j < M; j++) {
			score -= C[j] * (i + 1 - last[j]);
		}
	}
	return score;
}

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

	cin >> D;
	S.resize(D);
	for (int i = 0; i < M; i++) {
		cin >> C[i];
	}
	for (int i = 0; i < D; i++) {
		S[i].resize(M);
		for (int j = 0; j < M; j++) {
			cin >> S[i][j];
		}
	}

	pair<ll, vector<ll>> p = argmax<ll, vector<ll>>(10);

	for (int i = 0; i < D; i++) {
		cout << p.second[i] + 1 << endl;
	}

	return 0;
}

Compiler output:
a.cc:136:50: error: redeclaration of 'template<class T_score, class T_ans> T_ans generate(double)' may not have default arguments [-fpermissive]
  136 | template<typename T_score, typename T_ans> T_ans generate(double param = 0.9) { // ランダムに初期値を生成する
      |                                                  ^~~~~~~~
a.cc: In instantiation of 'std::pair<_T1, _T2> argmax(int) [with T_score = long long int; T_ans = std::vector<long long int>]':
a.cc:202:49:   required from here
  202 |         pair<ll, vector<ll>> p = argmax<ll, vector<ll>>(10);
      |                                  ~~~~~~~~~~~~~~~~~~~~~~^~~~
a.cc:119:44: error: no matching function for call to 'generate<long long int, std::vector<long long int, std::allocator<long long int> > >()'
  119 |         T_ans g0 = generate<T_score, T_ans>();
      |                    ~~~~~~~~~~~~~~~~~~~~~~~~^~
a.cc:136:50: note: candidate: 'template<class T_score, class T_ans> T_ans generate(double)'
  136 | template<typename T_score, typename T_ans> T_ans generate(double param = 0.9) { // ランダムに初期値を生成する
      |                                                  ^~~~~~~~
a.cc:136:50: note:   candidate expects 1 argument, 0 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algo.h:4345:5: note: candidate: 'template<class _FIter, class _Generator> void std::generate(_FIter, _FIter, _Generator)'
 4345 |     generate(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4345:5: note:   candidate expects 3 arguments, 0 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:200:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Generator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::generate(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _Generator)'
  200 | generate(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Generator __g);
      | ^~~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:200:1: note:   candidate expects 4 arguments, 0 provided
a.cc:122:51: error: no matching function for call to 'generate<long long int, std::vector<long long int, std::allocator<long long int> > >()'
  122 |                 T_ans g = generate<T_score, T_ans>();
      |                           ~~~~~~~~~~~~~~~~~~~~~~~~^~
a.cc:136:50: note: candidate: 'template<class T_score, class T_ans> T_ans generate(double)'
  136 | template<typename T_score, typename T_ans> T_ans generate(double param = 0.9) { // ランダムに初期値を生成する
      |                                                  ^~~~~~~~
a.cc:136:50: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_algo.h:4345:5: note: candidate: 'template<class _FIter, class _Generator> void std::generate(_FIter, _FIter, _Generator)'
 4345 |     generate(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4345:5: note:   candidate expects 3 arguments, 0 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:200:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Generator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::generate(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _Generator)'
  200 | generate(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Generator __g);
      | ^~~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:200:1: note:   candidate expects 4 arguments, 0 provided