Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sys/time.h>
 
using namespace std;
 
struct Timer {
  struct timeval start, cur;
  double limit;
	
  Timer() : limit(0) { gettimeofday(&start, NULL); }
  Timer(double l) : limit(l) { gettimeofday(&start, NULL); }
	
  bool isLimit() { return curTime() > limit; }
	
  double curTime() {
    gettimeofday(&cur, NULL);
    return (cur.tv_sec - start.tv_sec) + (cur.tv_usec - start.tv_usec) / 1e6;
  }
};
 
struct XorShift {
  unsigned int x, y, z, w;
 
  XorShift() { init(); }
  XorShift(unsigned int seed) { init(seed); }
 
  void init(unsigned int seed = 88675123) { x = 123456789; y = 362436069; z = 521288629; w = seed; }
 
  void setNext() {
    unsigned int t = x ^ (x << 11);
    x = y; y = z; z = w;
    w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
  }
  
  unsigned int nextUInt() { setNext(); return w; }
  unsigned int nextUInt(unsigned int n) { return nextUInt() % n; }
  double nextDouble() { return nextUInt() * (1.0 / 0xFFFFFFFFu); }
};
 
XorShift rnd(283);
double T = 10000.0;
double COLD = 0.999;
 
bool next(long long diff) {
  if (diff >= 0) return true;
  else return rnd.nextDouble() < exp(diff / T);
}

int D;
int c[26];
vector<vector<int>> s;
vector<int> ans;
 
// 初期解を生成
void generate_answer() {

  // 全部 0 にする
  /*
  for (int i = 0; i < D; i++) {
    ans[i] = 0;
  }
  */

  // 貪欲に一番いいやつを採用
  vector<int> last(26, 0);
  for (int i = 0; i < D; i++) {
    int val = -10101010;
    int id;
    for (int j = 0; j < 26; j++) {
      int tmp = s[i][j];
      for (int k = 0; k < 26; k++) {
        if (j == k) continue;
        tmp -= c[k] * (i + 1 - last[k]);
      }

      if (tmp > val) {
        id = j;
        val = tmp;
      }
    }

    last[id] = i + 1;
    ans[i] = id;
  }
}
 
// 答えを出力
void output_answer() {
  for (int i = 0; i < D; i++) {
    cout << ans[i] + 1 << endl;
  }
}

int getScore(vector<int> anss) {
  
  // 愚直にシミュレーションして得点計算
  // O(N * L + M * M)
  vector<int> last(26, 0);
  int score = 0;
  for (int i = 0; i < D; i++) {
    score += s[i][anss[i]];
    last[anss[i]] = i + 1;
    for (int j = 0; j < 26; j++) {
      score -= c[j] * (i + 1 - last[j]);
    }
  }

  return score;
}
 
int getScore() {
  
  // 愚直にシミュレーションして得点計算
  // O(N * L + M * M)
  vector<int> last(26, 0);
  int score = 0;
  for (int i = 0; i < D; i++) {
    score += s[i][ans[i]];
    last[ans[i]] = i + 1;
    for (int j = 0; j < 26; j++) {
      score -= c[j] * (i + 1 - last[j]);
    }
  }

  return score;
}

int scoreDiffNaive(vector<int> &before, vector<int> &after) {
  return getScore(after) - getScore(before);
}
 
void yakinamashi() {
  
  Timer timer(283);
  while (timer.curTime() < 1.9) {
    size_t d = rnd.nextUInt() % D;
    int maxScoreDiffNaive = -10101010;
    int q = -1;
    for (int j = 0; j < 26; j++) {
      auto nxt = ans;
      nxt[d] = j;
      int tmp = scoreDiffNaive(ans, nxt);
      if (tmp > maxScoreDiffNaive) {
        maxScoreDiffNaive = tmp;
        q = j;
      }
    }
    
    assert(q != -1);
    if(next(maxScoreDiffNaive)) ans[d] = q;
    T *= COLD;
    // cerr << T << " " << getScore() << endl;
  }
}
 
int main() {
  
  // 入力受け取り
  cin >> D;
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
  }

  s.resize(D);
  ans.resize(D);
  for (int i = 0; i < D; i++) {
    s[i].resize(26);
  }
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }
    
  // 初期解を生成
  generate_answer();
  
  // 時間いっぱい改善
  yakinamashi();
  // yamanobori();
 
  // 出力
  output_answer();
 
  return 0;
}


Compiler output:
a.cc: In function 'void yakinamashi()':
a.cc:152:5: error: 'assert' was not declared in this scope
  152 |     assert(q != -1);
      |     ^~~~~~
a.cc:6:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    5 | #include <sys/time.h>
  +++ |+#include <cassert>
    6 |