alexjercan/bugnet huggingface dataset:
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
#define all(a) a.begin(), a.end()
using ll = long long;
const int INF = 1 << 30;
const ll INFll = 1LL << 62;
const int mod = int(1e9) + 7;
using P = pair<ll, ll>;
using ld = long double;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  bool flg = true;
  for (int j = 0; j < k; ++j) {
    vector<ll> b(n + 1, 0);
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
      b[max(0LL, i - a[i])]++;
      b[min(i + a[i] + 1, n)]--;
      sum += min(a[i], (ll)i);
      sum += min(a[i], (ll)n - i - 1);
      sum++;
    }
    for (int i = 0; i < n; ++i) {
      b[i + 1] += b[i];
      a[i] = b[i];
    }
    if (sum >= n * n) {
      break;
    }
    //        cout <<sum<<endl;
  }
  for (int i = 0; i < n; ++i) {
    cout << a[i] << " ";
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define all(a) a.begin(), a.end()
using ll = long long;
const int INF = 1 << 30;
const ll INFll = 1LL << 62;
const int mod = int(1e9) + 7;
using P = pair<ll, ll>;
using ld = long double;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  bool flg = true;
  for (int j = 0; j < k; ++j) {
    vector<ll> b(n + 1, 0);
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
      b[max(0LL, i - a[i])]++;
      b[min(i + a[i] + 1, n)]--;
      sum += 2 * a[i] + 1;
    }
    for (int i = 0; i < n; ++i) {
      b[i + 1] += b[i];
      a[i] = b[i];
    }
    //            if(!flg)break;
    //        if(sum>=n*n){
    //            flg=false;
    //        }
  }
  for (int i = 0; i < n; ++i) {
    cout << a[i] << " ";
  }
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
void fn(int a, int b, int n, vector<int> &z) {
  static vector<int> d(n + 1, 0);
  if (a == -1) {
    z[0] = d[0];
    for (int i = 1; i < n; i++) {
      z[i] = d[i] + z[i - 1];
    }
    d = vector<int>(n + 1, 0);
  } else {
    d[a] += 1;
    d[b + 1] -= 1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> a(n), c(n, 0), d(n, 0), q(n, n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n; j++) {
      int k = max(0, j - a[j]), l = min(n - 1, j + a[j]);
      fn(k, l, n, c);
    }
    fn(-1, -1, n, c);
    a = c;
    c = d;
    if (a == q)
      break;
  }
  for (int i = 0; i < n; i++)
    cout << a[i] << " ";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
void fn(int a, int b, int n, vector<int> &z) {
  static vector<int> d(n + 1, 0);
  if (a == -1) {
    z[0] = d[0];
    for (int i = 1; i < n; i++) {
      z[i] = d[i] + z[i - 1];
    }
    d = vector<int>(n + 1, 0);
  } else {
    d[a] += 1;
    d[b + 1] -= 1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> a(n), c(n, 0), d(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  k = min(n, k);
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n; j++) {
      int k = max(0, j - a[j]), l = min(n - 1, j + a[j]);
      fn(k, l, n, c);
    }
    fn(-1, -1, n, c);
    a = c;
    c = d;
  }
  for (int i = 0; i < n; i++)
    cout << a[i] << " ";
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
typedef pair<int, int> P;
#define SORT(a) sort((a).begin(), (a).end())
#define rSORT(a) reverse((a).begin(), (a).end())
#define For(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) For(i, 0, n)
#define debug(x) cerr << #x << " = " << (x) << endl;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
// Write From this Line

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  k = min(50, k);
  rep(j, k) {
    vector<int> l(n), r(n);
    priority_queue<int, vector<int>, greater<int>> que;
    int L = 0, R = 0;
    rep(i, n) {
      while (que.size() && que.top() < (i + 1)) {
        L--;
        que.pop();
      }
      l[i] = L;
      L++;
      que.push((i + 1) + a[i]);
    }

    priority_queue<int> que2;
    for (int i = n - 1; i >= 0; i--) {
      while (que2.size() && que2.top() > (i + 1)) {
        R--;
        que2.pop();
      }
      r[i] = R;
      R++;
      que2.push((i + 1) - a[i]);
    }
    rep(i, n) { a[i] = l[i] + r[i] + 1; }
  }
  for (auto x : a) {
    cout << x << " ";
  }
  cout << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
typedef pair<int, int> P;
#define SORT(a) sort((a).begin(), (a).end())
#define rSORT(a) reverse((a).begin(), (a).end())
#define For(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) For(i, 0, n)
#define debug(x) cerr << #x << " = " << (x) << endl;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
// Write From this Line

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  k = min(1000, k);
  rep(j, k) {
    vector<int> l(n), r(n);
    priority_queue<int, vector<int>, greater<int>> que;
    int L = 0, R = 0;
    rep(i, n) {
      while (que.size() && que.top() < (i + 1)) {
        L--;
        que.pop();
      }
      l[i] = L;
      L++;
      que.push((i + 1) + a[i]);
    }

    priority_queue<int> que2;
    for (int i = n - 1; i >= 0; i--) {
      while (que2.size() && que2.top() > (i + 1)) {
        R--;
        que2.pop();
      }
      r[i] = R;
      R++;
      que2.push((i + 1) - a[i]);
    }
    rep(i, n) { a[i] = l[i] + r[i] + 1; }
  }
  for (auto x : a) {
    cout << x << " ";
  }
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
#define N 200005
int a[N], d[N];

int check(int n) {
  int i;
  for (i = 1; i <= n; i++) {
    if (a[i] != n)
      return 0;
  }
  return 1;
}

int main() {
  int n, k, i, l, r;
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }

  while (k--) {
    memset(d, 0, sizeof(d));
    for (i = 1; i <= n; i++) {
      l = i - a[i];
      r = i + a[i];
      if (l < 1)
        l = 1;
      if (r > n)
        r = n;
      d[r + 1] -= 1;
      d[l] += 1;
    }
    a[1] = d[1];
    for (i = 2; i <= n; i++) {
      d[i] += d[i - 1];
      a[i] = d[i];
    }
    if (check(n)) {
      for (i = 1; i <= n; i++) {
        cout << n << " ";
      }
      return 0;
    }
  }
  for (i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
#define N 200005
int a[N], d[N];

int check(int n) {
  int i;
  for (i = 1; i <= n; i++) {
    if (i != n)
      return 0;
  }
  return 1;
}

int main() {
  int n, k, i, l, r;
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }

  while (k--) {
    memset(d, 0, sizeof(d));
    for (i = 1; i <= n; i++) {
      l = i - a[i];
      r = i + a[i];
      if (l < 1)
        l = 1;
      if (r > n)
        r = n;
      d[r + 1] -= 1;
      d[l] += 1;
    }
    a[1] = d[1];
    for (i = 2; i <= n; i++) {
      d[i] += d[i - 1];
      a[i] = d[i];
    }
    if (check(n)) {
      for (i = 1; i <= n; i++) {
        cout << n << " ";
      }
      return 0;
    }
  }
  for (i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define srep(i, n, m) for (int i = n; i < m; i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int saidaikouyakusuu(int a, int b) {
  if (b == 0)
    return a;
  return saidaikouyakusuu(b, a % b);
}
int saisyoukoubaisuu(int a, int b) { return a * b / saidaikouyakusuu(a, b); }
int n, m, cnt = 0, aa[220000], ab[220000];
pair<int, int> pp[220000];
string s, ss[220000];
char c, ca;
queue<int> que;
signed main() {
  cin >> n >> m;
  rep(i, n) {
    cin >> aa[i];
    ab[max((long long)0, i - aa[i])]++;
    ab[min(n, i + aa[i] + 1)]--;
  }
  rep(i, min(m, (long long)100)) {
    rep(j, n) {
      aa[j] = ab[j] + aa[j - 1];
      ab[j] = 0;
    }
    rep(j, n) {
      ab[max((long long)0, j - aa[j])]++;
      ab[min(n, j + aa[j] + 1)]--;
    }
  }
  rep(i, n) { cout << aa[i] << ' '; }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
// constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define vmax 10000
// constexpr ll INF = 1e9+7;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
int n, k;
struct StarrySky {
  static const int MAX_N = 1 << 17;
  int datm[2 * MAX_N], data[2 * MAX_N], n;
  StarrySky() {}
  StarrySky(int n_) { init(n_); }
  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    for (int i = 0; i < n * 2; i++)
      datm[i] = data[i] = 0;
  }
  void add(int a, int b, int x, int k, int l, int r) {
    if (r <= a || b <= l)
      return;
    if (a <= l && r <= b) {
      data[k] += x;
      return;
    }
    add(a, b, x, k * 2 + 1, l, (l + r) / 2);
    add(a, b, x, k * 2 + 2, (l + r) / 2, r);
    datm[k] = max(datm[k * 2 + 1] + data[k * 2 + 1],
                  datm[k * 2 + 2] + data[k * 2 + 2]);
  }
  int query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return 0;
    if (a <= l && r <= b)
      return datm[k] + data[k];
    int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr) + data[k];
  }
  void add(int a, int b, int x) { add(a, b, x, 0, 0, n); }
  int query(int a, int b) { return query(a, b, 0, 0, n); }
};
int main() {
  cin >> n >> k;
  StarrySky ss(n);
  int a[n];
  rep(i, n) { cin >> a[i]; }
  rep(i, n) { ss.add(max(0, i - a[i]), min(n, i + a[i] + 1), 1); }
  rep(i, n) {
    int x = ss.query(i, i + 1);
    ss.add(max(0, i - a[i]), min(n, i + a[i] + 1), -1);
    ss.add(max(0, i - x), min(n, i + x + 1), 1);
  }
  rep(i, n) { cout << ss.query(i, i + 1) << " "; }
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main(int argc, const char *argv[]) {
  int n, op_cnt;
  cin >> n >> op_cnt;
  vector<int> va(n);
  for (auto &a : va) {
    cin >> a;
  }

  for (int i = 0; i < op_cnt; ++i) {
    vector<int> vaa(va.size(), 0);
    for (int j = 0; j < va.size(); ++j) {
      int a = va[j];
      int l_idx = max(0, j - a);
      vaa[l_idx]++;
      int r_idx = j + a + 1;
      if (r_idx < vaa.size()) {
        vaa[r_idx]--;
      }
    }

    va[0] = vaa[0];
    for (int j = 1; j < vaa.size(); ++j) {
      va[j] = va[j - 1] + vaa[j];
    }

    int min_el = *min_element(va.begin(), va.end());
    if (min_el >= n) {
      break;
    }
  }

  for (int j = 0; j < va.size(); ++j) {
    cout << va[j];
    if (j == va.size() - 1) {
      cout << '\\n';
    } else {
      cout << ' ';
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {
  int n, op_cnt;
  cin >> n >> op_cnt;
  vector<int> va(n);
  for (auto &a : va) {
    cin >> a;
  }

  for (int i = 0; i < op_cnt; ++i) {
    // 操作をする
    vector<int> vaa(va.size(), 0);
    for (int j = 0; j < va.size(); ++j) {
      for (int k = 0; k < va.size(); ++k) {
        int dist = abs(j - k);
        if (va[k] >= dist) {
          vaa[j]++;
        }
      }
    }

    int min_el = vaa.front();
    for (int j = 0; j < va.size(); ++j) {
      va[j] = vaa[j];
      min_el = min(min_el, va[j]);
      // if (va[j] >= 10) {
      // cout << vaa[j] << " ";
      // } else {
      // cout << '0' << vaa[j] << " ";
      // }
    }

    if (min_el == n) {
      break;
    }
    // cout << '\\n';
  }

  for (int j = 0; j < va.size(); ++j) {
    cout << va[j];
    if (j == va.size() - 1) {
      cout << '\\n';
    } else {
      cout << ' ';
    }
  }
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  if (n - 1 <= k) {
    REP(i, n) cout << n << " ";
    cout << '\\n';
    return 0;
  }

  REP(kk, k) {
    vector<int> tmp(n, 0);
    REP(i, n) {
      tmp[max(0, i - a[i])]++;
      if (i + a[i] + 1 <= n - 1)
        tmp[i + a[i] + 1]--;
    }
    REP(i, n - 1) tmp[i + 1] += tmp[i];

    a = tmp;
    bool flag = true;
    REP(i, n) if (a[i] < n) flag = false;
    if (flag)
      break;
  }

  REP(i, n) cout << a[i] << " ";
  cout << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  if (n <= k) {
    REP(i, n) cout << n << " ";
    cout << '\\n';
    return 0;
  }

  REP(kk, k) {
    vector<int> tmp(n, 0);
    REP(i, n) {
      if (a[i] == 0)
        tmp[i]++;
      else {
        FOR(j, max(0, i - a[i]), min(n, i + a[i] + 1)) { tmp[j]++; }
      }
    }
    a = tmp;
  }

  REP(i, n) cout << a[i] << " ";
  cout << '\\n';
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
const int N = 3e5 + 10;
const ll mod = 1e9 + 7;
ll pre[N], arr[N], k, n;
int main() {
  fast cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> arr[i];
  while (k--) {
    bool ans = true;
    for (int i = 1; i <= n; i++)
      if (arr[i] != n)
        ans = false;
    if (ans)
      break;
    for (ll i = 1; i <= n; i++) {
      ll x = max(1ll, i - arr[i]);
      ll y = min(n, arr[i] + i);
      pre[x] += 1;
      pre[y + 1] -= 1;
    }
    for (ll i = 1; i <= n; i++)
      pre[i] += pre[i - 1];
    for (int i = 1; i <= n; i++) {
      arr[i] = pre[i];
      pre[i] = 0;
    }
  }
  for (ll i = 1; i <= n; i++)
    cout << arr[i] << " ";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
const int N = 3e5 + 10;
const ll mod = 1e9 + 7;
ll pre[N], arr[N], k, n;
int main() {
  fast cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> arr[i];
  while (k--) {

    for (ll i = 1; i <= n; i++) {
      ll x = max(1ll, i - arr[i]);
      ll y = min(n, arr[i] + i);
      pre[x] += 1;
      pre[y + 1] -= 1;
    }
    for (ll i = 1; i <= n; i++)
      pre[i] += pre[i - 1];
    for (int i = 1; i <= n; i++) {
      arr[i] = pre[i];
      pre[i] = 0;
    }
  }
  for (ll i = 1; i <= n; i++)
    cout << arr[i] << " ";
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<ll>
#define rep(i, n) for (ll i = 0; i < (n); ++i)

int main() {

  ll N, K;
  cin >> N >> K;
  vl A(N);
  rep(i, N) cin >> A[i];

  ll n = 0;
  while (n < K) {
    vl B(N + 1, 0);
    rep(i, N) {
      if (i - A[i] <= 0)
        B[0]++;
      else
        B[i - A[i]]++;
      if (i + A[i] + 1 >= N)
        B[N]--;
      else
        B[i + A[i] + 1]--;
    }
    vl C(N, 0);
    bool ok = true;
    rep(i, N) {
      if (i > 0)
        C[i] = C[i - 1];
      C[i] += B[i];
      if (C[i] < N)
        ok = false;
    }
    if (ok) {
      rep(i, N) { cout << N << " "; }
      cout << endl;
      return 0;
    }
    n++;
    A = C;
  }

  rep(i, N) { cout << A[i] << " "; }
  cout << endl;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<ll>
#define rep(i, n) for (ll i = 0; i < (n); ++i)

int main() {

  ll N, K;
  cin >> N >> K;
  vl A(N);
  rep(i, N) cin >> A[i];

  ll n = 0;
  while (n < K) {
    vl B(N + 1, 0);
    rep(i, N) {
      if (i - A[i] <= 0)
        B[0]++;
      else
        B[i - A[i]]++;
      if (i + A[i] > N)
        B[N]--;
      else
        B[i + A[i] + 1]--;
    }
    vl C(N, 0);
    bool ok = true;
    rep(i, N) {
      if (i > 0)
        C[i] = C[i - 1];
      C[i] += B[i];
      if (C[i] < N)
        ok = false;
    }
    if (ok) {
      rep(i, N) { cout << N << " "; }
      cout << endl;
      return 0;
    }
    n++;
    A = C;
  }

  rep(i, N) { cout << A[i] << " "; }
  cout << endl;

  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int j = 0; j < k; j++) {
    vector<int> b(n + 1);
    for (int i = 0; i < n; i++) {
      int l = max(0, i - a.at(i));
      int r = min(i + a.at(i) + 1, n);
      b.at(l)++;
      b.at(r)--;
    }
    for (int i = 0; i < n; i++) {
      b.at(i + 1) += b.at(i);
    }
    b.pop_back();
    if (a == b) {
      break;
    }
    a = b;
  }
  for (int i = 0; i < n; i++) {
    cout << a.at(i) << endl;
  }

  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 6) >= this->size() (which is 6)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n + 1);
  for (int i = 1; i < n + 1; i++) {
    cin >> a.at(i);
  }
  for (int j = 0; j < k; j++) {

    vector<int> s(n + 2, 0);
    for (int i = 1; i < n + 1; i++) {
      if (i - a.at(i) < 0) {
        s.at(0)++;
      } else {
        s.at(i - a.at(i))++;
      }
      if (i + 1 + a.at(i) > n + 1) {
        s.at(n + 1)--;
      } else {
        a.at(i + 1 + a.at(i))--;
      }
    }
    a.at(0) = s.at(0);
    for (int i = 1; i < n + 1; i++) {
      a.at(i) = a.at(i - 1) + s.at(i);
    }
    bool c = false;
    for (int i = 1; i < n + 1; i++) {
      if (a.at(i) != n) {
        c = true;
      }
    }
    if (c == false) {
      break;
    }
  }

  for (int i = 1; i < n + 1; i++) {
    cout << a.at(i) << endl;
  }

  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define endl '\\n'
#define ll long long
#define FASTINOUT                                                              \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
const int N = 1e6 + 9;
ll y[N];
ll sum[N];
int main() {
  FASTINOUT;
  ll x, k;
  cin >> x >> k;
  int c = 0;
  for (int i = 1; i <= x; i++) {
    cin >> y[i];
    if (y[i])
      c++;
  }
  if (k >= x - 1) {
    for (int i = 1; i <= x; i++)
      cout << x << " ";
    return 0;
  }
  for (int j = 1; j <= k; j++) {
    memset(sum, 0, sizeof sum);
    for (ll i = 1; i <= x; i++) {
      sum[max(i - y[i], 1LL)]++;
      sum[min(i + y[i] + 1, x + 1)]--;
    }
    int cnt = 0;
    for (int i = 1; i <= x; i++) {
      sum[i] += sum[i - 1];
      y[i] = sum[i];
      if (y[i] < x)
        cnt++;
    }
    if (!cnt)
      break;
  }
  for (int i = 1; i <= x; i++)
    cout << sum[i] << " ";
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define endl '\\n'
#define ll long long
#define FASTINOUT                                                              \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
const int N = 1e5 + 9;
ll y[N];
ll sum[N];
int main() {
  FASTINOUT;
  ll x, k;
  cin >> x >> k;
  int c = 0;
  for (int i = 1; i <= x; i++) {
    cin >> y[i];
    if (y[i])
      c++;
  }
  if (!c) {
    for (int i = 1; i <= x; i++)
      cout << 1 << " ";
    return 0;
  }
  if (k >= x - 1) {
    for (int i = 1; i <= x; i++)
      cout << x << " ";
    return 0;
  }
  for (int j = 1; j <= k; j++) {
    memset(sum, 0, sizeof sum);
    for (ll i = 1; i <= x; i++) {
      sum[max(i - y[i], 1LL)]++;
      sum[min(i + y[i] + 1, x + 1)]--;
    }
    int cnt = 0;
    for (int i = 1; i <= x; i++) {
      sum[i] += sum[i - 1];
      y[i] = sum[i];
      if (y[i] < x)
        cnt++;
    }
    if (!cnt)
      break;
  }
  for (int i = 1; i <= x; i++)
    cout << sum[i] << " ";
  return 0;
}