Problem p02618 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <chrono>
#include <cmath>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <random>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// 変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

// for簡易表記(引数ミス防止)
#define FOR(LoopVariable, numberOFbegin, numberOFend)                          \\
  for (long long int LoopVariable = (numberOFbegin);                           \\
       (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable, numberOFbegin, numberOFend)                        \\
  for (long long int LoopVariable = (numberOFbegin)-1;                         \\
       (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable, numberOFend)                                         \\
  for (long long int LoopVariable = 0; (LoopVariable) < (numberOFend);         \\
       LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max() - 5;
constexpr int inf = numeric_limits<int>::max() - 5;
constexpr long long int mod = 1000000007;

using llint = long long;

llint scoring(vector<llint> c, vector<vector<llint>> s, vector<llint> result,
              llint d = 365) {

  if (c.size() != s[0].size() || s.size() != result.size()) {
    return -1;
  } else {
    llint score = 0;
    REP(i, d) {
      score += s[i][result[i] - 1];
      REP(j, 26) {
        if (j + 1 != result[i]) {
          score -= c[j];
        }
      }
    }
    return score;
  }
}

int main() {
  chrono::system_clock::time_point start, end;
  std::random_device rnd; // 非決定的な乱数生成器を生成
  std::mt19937 mt(
      rnd()); //  メルセンヌ・ツイスタの32ビット版、引数は初期シード値
  start = chrono::system_clock::now();
  llint d;
  cin >> d;
  std::uniform_int_distribution<> rand26(1, 26),
      randd(0, d - 1); // [0, 99] 範囲の一様乱数

  llint anum = 26;
  vector<llint> c(anum);

  REP(i, anum) { cin >> c[i]; }
  vector<vector<llint>> s(d, vector<llint>(anum));
  REP(i, d) {
    REP(j, anum) { cin >> s[i][j]; }
  }
  vector<llint> result(d);

  REP(i, d) { result[i] = 1 + i % 26; }
  double time;
  while ((time = static_cast<double>(
              chrono::duration_cast<chrono::microseconds>(
                  (end = chrono::system_clock::now()) - start)
                  .count())) < 1800) {
    auto newresult = result;
    REP(i, 3) { newresult[randd(mt)] = rand26(mt); }
    if (scoring(c, s, newresult, d) > scoring(c, s, result, d)) {
      result = newresult;
    }
  }
  REP(i, d) { cout << result[i] << endl; }
}


Error: WA

Fixed submission:

#include <algorithm>
#include <array>
#include <chrono>
#include <cmath>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <random>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// 変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

// for簡易表記(引数ミス防止)
#define FOR(LoopVariable, numberOFbegin, numberOFend)                          \\
  for (long long int LoopVariable = (numberOFbegin);                           \\
       (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable, numberOFbegin, numberOFend)                        \\
  for (long long int LoopVariable = (numberOFbegin)-1;                         \\
       (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable, numberOFend)                                         \\
  for (long long int LoopVariable = 0; (LoopVariable) < (numberOFend);         \\
       LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max() - 5;
constexpr int inf = numeric_limits<int>::max() - 5;
constexpr long long int mod = 1000000007;

using llint = long long;

llint scoring(vector<llint> c, vector<vector<llint>> s, vector<llint> result) {

  if (c.size() != s[0].size() || s.size() != result.size()) {
    return -1;
  } else {
    return 1;
  }
}

int main() {
  chrono::system_clock::time_point start, end;
  std::random_device rnd; // 非決定的な乱数生成器を生成
  std::mt19937 mt(
      rnd()); //  メルセンヌ・ツイスタの32ビット版、引数は初期シード値
  start = chrono::system_clock::now();
  llint d;
  cin >> d;
  std::uniform_int_distribution<> rand26(1, 26),
      randd(0, d - 1); // [0, 99] 範囲の一様乱数

  llint anum = 26;
  vector<llint> c(anum);

  REP(i, anum) { cin >> c[i]; }
  vector<vector<llint>> s(d, vector<llint>(anum));
  REP(i, d) {
    REP(j, anum) { cin >> s[i][j]; }
  }
  vector<llint> result(anum);

  REP(i, d) { result[i] = 1 + i % 26; }
  double time;
  while ((time = static_cast<double>(
              chrono::duration_cast<chrono::microseconds>(
                  (end = chrono::system_clock::now()) - start)
                  .count() /
              1000.0)) < 1800) {
    auto newresult = result;
    REP(i, 3) { newresult[randd(mt)] = rand26(mt); }
    if (scoring(c, s, newresult) > scoring(c, s, result)) {
      result = newresult;
    }
  }
  REP(i, d) { cout << result[i] << endl; }
}