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

#include <bits/stdc++.h>

#define rep2(x, fr, to) for (int x = (fr); x < (to); x++)
#define rep(x, to) for (int x = 0; x < (to); x++)
#define repr(x, fr, to) for (int x = (fr); x >= (to); x--)
#define all(c) c.begin(), c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, int> pii;
typedef vector<ll> VL;
const int MD = 1e9 + 7;
void dbg() { cerr << "\\n"; }
template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) {
  cerr << fst << ": ";
  dbg(rst...);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int k, n;
  cin >> k >> n;
  VI a(2 * n);
  rep(i, n) {
    cin >> a[i];
    a[i + n] = a[i] + k;
  }
  int mx = 0;
  rep(i, 2 * n - 1) { mx = max(mx, a[i + 1] - a[i]); }
  cout << k - mx << "\\n";
  return 0;
}


Error: WA

Fixed submission:

#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#include <x86intrin.h>

#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--)
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
const int MD = (int)1e9 + 7;
typedef vector<ll> VL;
void dbg() { cerr << "\\n"; }
template <class T, class... T2> void dbg(const T &fst, const T2 &...rst) {
  cerr << fst << ": ";
  dbg(rst...);
}
template <class T, class T2> void amax(T &a, T2 b) {
  if (a < b)
    a = b;
}

const int NMX = 2048;
int16_t d[NMX][NMX];

void f1(int N) {
  for (int k = 0; k < N; k++)
    for (int i = 0; i < N; i++) {
      int j = 0;
      const __m128i dik = _mm_set1_epi16(d[i][k]);
      for (; j + 7 < N; j += 8) {
        __m128i dij = _mm_load_si128((__m128i *)(d[i] + j));
        __m128i dkj = _mm_load_si128((__m128i *)(d[k] + j));
        dkj = _mm_add_epi16(dkj, dik);
        dij = _mm_min_epi16(dij, dkj);
        _mm_store_si128((__m128i *)(d[i] + j), dij);
      }

      for (; j < N; j++) {
        d[i][j] = min<int>(d[i][j], d[i][k] + d[k][j]);
      }
    }
}
/*
void f2(int N){
        for (int k = 0; k < N; k++) for (int i = 0; i < N; i++){
                int j = 0;
                const __m256i dik = _mm256_set1_epi16(d[i][k]);
                for (;j+15<N;j+=16){
                        __m256i dij = _mm256_load_si256((__m256i*)(d[i] + j));
                        __m256i dkj = _mm256_load_si256((__m256i*)(d[k] + j));
                        dkj = _mm256_add_epi16(dkj, dik);
                        dij = _mm256_min_epi16(dij, dkj);
                        _mm256_store_si256((__m256i*)(d[i] + j), dij);
                }

                for (;j<N;j++){
                  d[i][j] = min<int>(d[i][j], d[i][k] + d[k][j]);
                }
        }
}
*/
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll n, x, y;
  cin >> n >> x >> y;
  // vector<VI> a(n, VI(n, INF));
  // rep(i, n) a[i][i] = 0;
  // rep(i, n-1) a[i][i+1] = a[i+1][i] =1;
  // a[x-1][y-1] = a[y-1][x-1] =1;
  // rep(k,n) rep(i,n) rep(j,n) a[i][j] =min(a[i][j], a[i][k] + a[k][j]);

  rep(i, n + 2) rep(j, n + 2) d[i][j] = n;
  rep(i, n) d[i][i] = 0;
  rep(i, n - 1) d[i][i + 1] = d[i + 1][i] = 1;
  d[x - 1][y - 1] = d[y - 1][x - 1] = 1;
  f1(n);
  // dbg("dd");
  VI ds(n + 2);
  rep(i, n) rep2(j, i + 1, n) ds[d[i][j]]++;

  // for(auto x :ds) cerr<<x<<" "; dbg();
  rep2(i, 1, n) cout << ds[i] << "\\n";
  return 0;

  return 0;
}