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

#include "bits/stdc++.h"
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void ran() { srand(chrono::steady_clock::now().time_since_epoch().count()); }
long long get_rand() {
  long long a = rand();
  long long b = rand();
  return a * (RAND_MAX + 1ll) + b;
}
// #define endl '\\n'
// #define double long double
#define int long long
// int MOD = 1000 * 1000 * 1000 + 7;
// int MOD = 998244353;

signed main() {

  ran();
  fast();

  int n, k;
  cin >> n >> k;
  int arr[n];
  bool alln = true;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] != n)
      alln = false;
  }

  for (int i = 0; i < k; i++) {
    if (alln)
      continue;
    vector<pair<int, int>> events;
    for (int j = 0; j < n; j++) {
      events.push_back(make_pair(j - arr[j], 1));
      events.push_back(make_pair(j + arr[j] + 1, -1));
    }

    sort(events.begin(), events.end());

    int at = 0;
    int cur = 0;
    for (int j = 0; j < n; j++) {
      while (at < events.size() && events[at].first <= j) {
        cur += events[at].second;
        at++;
      }
      arr[j] = cur;
    }

    alln = true;
    for (int j = 0; j < n; j++) {
      // cout << arr[j] << ' ';
      if (arr[j] != n)
        alln = false;
    }
    // cout << endl;
  }

  for (int i = 0; i < n; i++) {
    cout << arr[i] << ' ';
  }
  cout << endl;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void ran() { srand(chrono::steady_clock::now().time_since_epoch().count()); }
long long get_rand() {
  long long a = rand();
  long long b = rand();
  return a * (RAND_MAX + 1ll) + b;
}
// #define endl '\\n'
// #define double long double
#define int long long
// int MOD = 1000 * 1000 * 1000 + 7;
// int MOD = 998244353;

signed main() {

  ran();
  fast();

  int n, k;
  cin >> n >> k;
  int arr[n];
  bool alln = true;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] != n)
      alln = false;
  }

  for (int i = 0; i < k; i++) {
    if (alln)
      continue;

    vector<pair<int, int>> events;
    for (int j = 0; j < n; j++) {
      events.push_back(make_pair(j - arr[j], 1));
      events.push_back(make_pair(j + arr[j] + 1, -1));
    }

    sort(events.begin(), events.end());

    int at = 0;
    int cur = 0;
    for (int j = 0; j < n; j++) {
      while (at < events.size() && events[at].first <= j) {
        cur += events[at].second;
        at++;
      }
      arr[j] = cur;
    }

    for (int j = 0; j < n; j++) {
      if (arr[j] != n)
        alln = false;
    }
  }

  for (int i = 0; i < n; i++) {
    cout << arr[i] << ' ';
  }
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto &&e : a) {
    cin >> e;
  }

  for (int i = 0; i < min(k, 100); ++i) {
    vector<int> tmp(n, 0);
    for (int j = 0; j < n; ++j) {
      int l = max(0, j - a[j]);
      int r = j + a[j] + 1;
      tmp[l] += 1;
      if (n > r)
        tmp[r] -= 1;
    }
    for (int i = 0; i < n - 1; ++i) {
      a[i] = tmp[i];
      tmp[i + 1] += tmp[i];
    }
    a[n - 1] = tmp[n - 1];
  }
  for (auto &&e : a) {
    cout << e << " ";
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto &&e : a) {
    cin >> e;
  }

  for (int i = 0; i < k; ++i) {
    vector<int> tmp(n, 0);
    for (int j = 0; j < n; ++j) {
      int l = max(0, j - a[j]);
      int r = j + a[j] + 1;
      tmp[l] += 1;
      if (n > r)
        tmp[r] -= 1;
    }
    for (int i = 0; i < n - 1; ++i) {
      a[i] = tmp[i];
      tmp[i + 1] += tmp[i];
    }
    a[n - 1] = tmp[n - 1];
  }
  for (auto &&e : a) {
    cout << e << " ";
  }
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#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);
  }

  vector<int> B;
  for (int i = 0; i < K; i++) {
    B = vector<int>(N, 0);

    for (int j = 0; j < N; j++) {
      int a = A.at(j); // A_j
      int left = max(j - a, 0);
      int right = min(j + a, N - 1);
      B.at(left)++;
      if (right != N - 1) {
        B.at(right + 1)--;
      }
    }

    for (int j = 1; j < N; j++) {
      B.at(j) += B.at(j - 1);
    }

    if (A == B) {
      break;
    }

    swap(A, B);
  }

  for (int i = 0; i < N; i++) {
    cout << A.at(i);
    if (i == N - 1) {
      cout << endl;
    } else {
      cout << ' ';
    }
  }
}


Error: TLE

Fixed submission:

#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);
  }

  if (N <= K) {
    for (int i = 0; i < N; i++) {
      cout << N;
      if (i == N - 1) {
        cout << endl;
      } else {
        cout << ' ';
      }
    }
    return 0;
  }

  vector<int> B;
  for (int i = 0; i < K; i++) {
    B = vector<int>(N, 0);

    for (int j = 0; j < N; j++) {
      int a = A.at(j); // A_j
      int left = max(j - a, 0);
      int right = min(j + a, N - 1);
      // for (int k = left; k < right + 1; k++) {
      //   B.at(k)++;
      // }
      B.at(left)++;
      if (right != N - 1) {
        B.at(right + 1)--;
      }
    }
    // A = B;
    int a = 0;
    for (int j = 0; j < N; j++) {
      a += B.at(j);
      A.at(j) = a;
    }
  }

  for (int i = 0; i < N; i++) {
    cout << A.at(i);
    if (i == N - 1) {
      cout << endl;
    } else {
      cout << ' ';
    }
  }
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#define re register
const int MAXN = 2e5 + 10;
int n, K, s[MAXN], a[MAXN], timee;
char fin[10010], *p1 = fin, *p2 = fin;
char getc() {
  return p1 == p2 && (p2 = (p1 = fin) + fread(fin, 1, 10000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
int read() {
  re int x = 0;
  re char ch = 0;
  while (ch < '0' || ch > '9')
    ch = getc();
  while ('0' <= ch && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getc();
  return x;
}
inline void insert(int x, int w) {
  for (; x <= n; x += x & -x)
    s[x] += w;
}
inline int query(int x) {
  re int res = 0;
  for (; x; x -= x & -x)
    res += s[x];
  return res;
}
int main() {
  // freopen("t2.out","w",stdout);
  n = read();
  K = read();
  for (re int i = 1; i <= n; i++)
    a[i] = read();
  if (K >= 41) {
    for (re int i = 1; i <= n; i++)
      printf("%d ", n);
    return 0;
  }
  while (K--) {
    re bool flag = 1;
    memset(s, 0, (n + 5) * sizeof(int));
    for (re int i = 1; i <= n; i++)
      insert(std::max(1, i - a[i]), 1), insert(std::min(n, i + a[i]) + 1, -1);
    for (re int i = 1; i <= n; i++)
      a[i] = query(i), flag &= (a[i] == n);
    if (flag)
      break;
  }
  for (re int i = 1; i <= n; i++)
    printf("%d ", a[i]);
  printf("\\n");
  return 0;
}
/*
5 1
1 0 0 1 0
*/

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#define re register
const int MAXN = 2e5 + 10;
int n, K, s[MAXN], a[MAXN], timee;
char fin[10010], *p1 = fin, *p2 = fin;
char getc() {
  return p1 == p2 && (p2 = (p1 = fin) + fread(fin, 1, 10000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
int read() {
  re int x = 0;
  re char ch = 0;
  while (ch < '0' || ch > '9')
    ch = getc();
  while ('0' <= ch && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getc();
  return x;
}
inline void insert(int x, int w) {
  for (; x <= n; x += x & -x)
    s[x] += w;
}
inline int query(int x) {
  re int res = 0;
  for (; x; x -= x & -x)
    res += s[x];
  return res;
}
int main() {
  freopen("t2.in", "r", stdin);
  // freopen("t2.out","w",stdout);
  n = read();
  K = read();
  for (re int i = 1; i <= n; i++)
    a[i] = read();
  if (K >= 41) {
    for (re int i = 1; i <= n; i++)
      printf("%d ", n);
    return 0;
  }
  while (K--) {
    re bool flag = 1;
    memset(s, 0, (n + 5) * sizeof(int));
    for (re int i = 1; i <= n; i++)
      insert(std::max(1, i - a[i]), 1), insert(std::min(n, i + a[i]) + 1, -1);
    for (re int i = 1; i <= n; i++)
      a[i] = query(i), flag &= (a[i] == n);
    if (flag)
      break;
  }
  for (re int i = 1; i <= n; i++)
    printf("%d ", a[i]);
  printf("\\n");
  return 0;
}
/*
5 1
1 0 0 1 0
*/
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#define re register
const int MAXN = 2e5 + 10;
int n, K, s[MAXN], a[MAXN], timee;
char fin[10010], *p1 = fin, *p2 = fin;
char getc() {
  return p1 == p2 && (p2 = (p1 = fin) + fread(fin, 1, 10000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
int read() {
  re int x = 0;
  re char ch = 0;
  while (ch < '0' || ch > '9')
    ch = getc();
  while ('0' <= ch && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getc();
  return x;
}
inline void insert(int x, int w) {
  for (; x <= n; x += x & -x)
    s[x] += w;
}
inline int query(int x) {
  re int res = 0;
  for (; x; x -= x & -x)
    res += s[x];
  return res;
}
int main() {
  // freopen("t2.out","w",stdout);
  n = read();
  K = read();
  for (re int i = 1; i <= n; i++)
    a[i] = read();
  while (K--) {
    re bool flag = 1;
    memset(s, 0, (n + 5) * sizeof(int));
    for (re int i = 1; i <= n; i++)
      insert(std::max(1, i - a[i]), 1), insert(std::min(n, i + a[i]) + 1, -1);
    for (re int i = 1; i <= n; i++)
      a[i] = query(i), flag &= (a[i] == n);
    if (flag)
      break;
  }
  for (re int i = 1; i <= n; i++)
    printf("%d ", a[i]);
  printf("\\n");
  return 0;
}
/*
5 1
1 0 0 1 0
*/

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#define re register
const int MAXN = 2e5 + 10;
int n, K, s[MAXN], a[MAXN], timee;
char fin[10010], *p1 = fin, *p2 = fin;
char getc() {
  return p1 == p2 && (p2 = (p1 = fin) + fread(fin, 1, 10000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
int read() {
  re int x = 0;
  re char ch = 0;
  while (ch < '0' || ch > '9')
    ch = getc();
  while ('0' <= ch && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getc();
  return x;
}
inline void insert(int x, int w) {
  for (; x <= n; x += x & -x)
    s[x] += w;
}
inline int query(int x) {
  re int res = 0;
  for (; x; x -= x & -x)
    res += s[x];
  return res;
}
int main() {
  freopen("t2.in", "r", stdin);
  // freopen("t2.out","w",stdout);
  n = read();
  K = read();
  for (re int i = 1; i <= n; i++)
    a[i] = read();
  while (K--) {
    re bool flag = 1;
    memset(s, 0, (n + 5) * sizeof(int));
    for (re int i = 1; i <= n; i++)
      insert(std::max(1, i - a[i]), 1), insert(std::min(n, i + a[i]) + 1, -1);
    for (re int i = 1; i <= n; i++)
      a[i] = query(i), flag &= (a[i] == n);
    if (flag)
      break;
  }
  for (re int i = 1; i <= n; i++)
    printf("%d ", a[i]);
  printf("\\n");
  return 0;
}
/*
5 1
1 0 0 1 0
*/
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int n, k;
int a[200005];
int sum[200005];

int main(void) {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 0; i < k; i++) {
    memset(sum, 0, sizeof(sum));
    bool flag = true;
    for (int j = 0; j < n; j++) {
      if (a[j] != n) {
        flag = false;
      }
    }
    if (flag)
      break;
    for (int j = 0; j < n; j++) {
      sum[max(0, j - a[j])]++;
      sum[min(n, j + a[j] + 1)]--;
    }
    for (int j = 0; j < n; j++) {
      sum[j + 1] += sum[j];
      a[j] = sum[j];
    }
  }
  for (int i = 0; i < n; i++) {
    printf("%d%c", a[i], i + 1 == n ? '\\n' : ' ');
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int n, k;
int a[200005];
int sum[200005];

int main(void) {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 0; i < k; i++) {
    memset(sum, 0, sizeof(sum));
    bool flag = true;
    for (int j = 0; j < n; j++) {
      if (a[j] != n) {
        flag = false;
      }
    }
    for (int j = 0; j < n; j++) {
      sum[max(0, j - a[j])]++;
      sum[min(n, j + a[j] + 1)]--;
    }
    for (int j = 0; j < n; j++) {
      sum[j + 1] += sum[j];
      a[j] = sum[j];
    }
  }
  for (int i = 0; i < n; i++) {
    printf("%d%c", a[i], i + 1 == n ? '\\n' : ' ');
  }
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

// Data
const int N = 2e5;
int n, k, a[N + 7];

// Fenwicktree
int c[2][N + 7];
void add(int c[], int x, int y) {
  for (int i = x; i <= n; i += i & -i)
    c[i] += y;
}
int sum(int c[], int x) {
  int y = 0;
  for (int i = x; i >= 1; i -= i & -i)
    y += c[i];
  return y;
}

// Main
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int j = 1; j <= k; j++) {
    fill(c[j & 1] + 1, c[j & 1] + n + 1, 0);
    for (int i = 1; i <= n; i++)
      add(c[j & 1], max(i - a[i], 1), 1),
          add(c[j & 1], min(i + a[i], n) + 1, -1);
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      a[i] = sum(c[j & 1], i);
      if (a[i] == n)
        cnt++;
    }
    if (cnt == n)
      break;
  }
  for (int i = 1; i <= n; i++)
    printf("%d ", a[i]);
  putchar(10);
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

// Data
const int N = 2e5;
int n, k, a[N + 7];

// Fenwicktree
int c[2][N + 7];
void add(int c[], int x, int y) {
  for (int i = x; i <= n; i += i & -i)
    c[i] += y;
}
int sum(int c[], int x) {
  int y = 0;
  for (int i = x; i >= 1; i -= i & -i)
    y += c[i];
  return y;
}

// Main
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int j = 1; j <= k; j++) {
    fill(c[j & 1] + 1, c[j & 1] + n + 1, 0);
    for (int i = 1; i <= n; i++)
      add(c[j & 1], max(i - a[i], 1), 1),
          add(c[j & 1], min(i + a[i], n) + 1, -1);
    for (int i = 1; i <= n; i++)
      a[i] = sum(c[j & 1], i);
  }
  for (int i = 1; i <= n; i++)
    printf("%d ", a[i]);
  putchar(10);
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vi = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM                                                              \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false)
#define all(x) x.begin(), x.end()
#define rep(i, sta, end) for (ll i = sta; i < end; ++i)
#define lcm(a, b) (a) / __gcd((a), (b)) * (b)
#define pb push_back
#define INF 1000000000000000LL
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a, b, c, d) // cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
// DBG("","","","");

signed main() {
  IO_STREAM;
  int N, K;
  cin >> N >> K;
  vi A(N);
  rep(i, 0, N) { cin >> A[i]; }
  rep(cnt, 0, K) {
    vi B(N + 1);
    rep(i, 0, N) {
      int st, ed;
      st = max((int)(i - A[i]), 0);
      ed = min((int)(i + A[i] + 1), N);
      B[st]++;
      B[ed]--;
    }
    rep(i, 0, N) { B[i + 1] += B[i]; }
    if (A == B)
      break;
    A = B;
    B[N] = 0;
  }
  rep(i, 0, N) { cout << A[i] << ' '; }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vi = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM                                                              \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false)
#define all(x) x.begin(), x.end()
#define rep(i, sta, end) for (ll i = sta; i < end; ++i)
#define lcm(a, b) (a) / __gcd((a), (b)) * (b)
#define pb push_back
#define INF 1000000000000000LL
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a, b, c, d) // cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
// DBG("","","","");

signed main() {
  IO_STREAM;
  int N, K;
  cin >> N >> K;
  vi A(N);
  rep(i, 0, N) { cin >> A[i]; }
  rep(cnt, 0, K) {
    vi B(N + 1);
    rep(i, 0, N) {
      int st, ed;
      st = max((int)(i - A[i]), 0);
      ed = min((int)(i + A[i] + 1), N);
      B[st]++;
      B[ed]--;
    }
    rep(i, 0, N) { B[i + 1] += B[i]; }
    //		if(A==B) break;
    A = B;
    B[N] = 0;
  }
  rep(i, 0, N) { cout << A[i] << ' '; }
  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 + 1, 0);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < 41; i++) {
    if (i == k)
      break;
    vector<int> imos(n, 0);
    for (int j = 0; j < n; j++) {
      int l = max(0, j - a[j]);
      int r = min(n - 1, j + a[j]);
      imos[l]++;
      imos[r + 1]--;
    }
    for (int j = 0; j < n; j++)
      imos[j + 1] += imos[j];
    a = imos;
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << ((i + 1 < n) ? ' ' : '\\n');
  }
}

Error: 0

Fixed submission:

#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[i];
  for (int i = 0; i < 41; i++) {
    if (i == k)
      break;
    vector<int> imos(n, 0);
    for (int j = 0; j < n; j++) {
      int l = max(0, j - a[j]);
      int r = min(n - 1, j + a[j]);
      imos[l]++;
      if (r + 1 < n)
        imos[r + 1]--;
    }
    for (int j = 0; j < n; j++)
      imos[j + 1] += imos[j];
    a = imos;
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << ((i + 1 < n) ? " " : "\\n");
  }
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using ll = long long;

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
const ll MOD = 1e9 + 7;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> as(n);
  rep(i, n) cin >> as[i];
  rep(i, k) {
    vector<int> dps(n + 1, 0);
    rep(j, n) {
      int a = as[j];
      int lb = max(0, j - as[j]), mb = min(n - 1, j + as[j]);
      dps[lb]++;
      dps[mb + 1]--;
    }
    int aa = 0;
    rep(l, n) {
      aa += dps[l];
      as[l] = aa;
    }
    bool isdone = true;
    for (int a : as) {
      if (a != n) {
        isdone = false;
        break;
      }
    }
    if (isdone)
      break;
  }
  for (int a : as)
    cout << a << " ";
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

using ll = long long;

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
const ll MOD = 1e9 + 7;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> as(n);
  rep(i, n) cin >> as[i];
  rep(i, k) {
    vector<int> bs(n, 0);
    rep(j, n) {
      int a = as[j];
      for (int ib = max(0, j - as[j]); ib <= min(n - 1, j + as[j]); ++ib) {
        bs[ib] += 1;
      }
    }
    swap(as, bs);
    bool isdone = true;
    for (int a : as) {
      if (a != n) {
        isdone = false;
        break;
      }
    }
    if (isdone)
      break;
  }
  for (int a : as)
    cout << a << " ";
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define DIM 200005
using namespace std;
int n, i, k, ok;
int a[DIM], b[DIM];
int main() {
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (; k; k--) {
    for (i = 1; i <= n; i++) {
      b[max(1, i - a[i])]++;
      b[min(n + 1, i + a[i] + 1)]--;
    }
    for (i = 1; i <= n; i++) {
      b[i] += b[i - 1];
    }
    ok = 0;
    for (i = 1; i <= n; i++) {
      a[i] = b[i];
      b[i] = 0;
      if (a[i] != n) {
        ok = 1;
      }
    }
    if (ok == 0) {
      break;
    }
  }
  for (i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
}


Error: WA

Fixed submission:

#include <iostream>
#define DIM 100005
using namespace std;
int n, i, k, ok;
int a[DIM], b[DIM];
int main() {
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (; k; k--) {
    for (i = 1; i <= n; i++) {
      b[max(1, i - a[i])]++;
      b[min(n + 1, i + a[i] + 1)]--;
    }
    for (i = 1; i <= n; i++) {
      b[i] += b[i - 1];
    }
    ok = 0;
    for (i = 1; i <= n; i++) {
      a[i] = b[i];
      b[i] = 0;
      if (a[i] != n) {
        ok = 1;
      }
    }
    if (ok == 0) {
      break;
    }
  }
  for (i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

/**
 *    author:  tourist
 *    created: 13.06.2020 15:34:38
 **/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b(n + 1);
  while (k--) {
    for (int i = 0; i <= n; i++) {
      b[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      int from = max(i - a[i], 0);
      int to = min(i + a[i], n - 1);
      b[from] += 1;
      b[to + 1] -= 1;
    }
    bool changed = false;
    for (int i = 0; i < n; i++) {
      changed |= (a[i] != b[i]);
      a[i] = b[i];
      b[i + 1] += b[i];
    }
    if (!changed) {
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << a[i];
  }
  cout << '\\n';
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {

  int n, k, temp = 0;
  cin >> n >> k;
  vector<int> a;
  for (int i = 0; i < n; ++i) {
    cin >> temp;
    a.push_back(temp);
  }
  int lower = 0, upper = 0;
  for (int j = 0; j < k; ++j) {
    for (int i = 3; i < n - 3; ++i) {
      int x = a[i];
      lower = (int)(i - a[i] - 0.5);
      upper = (int)(i + a[i] + 0.5);
      for (int i = lower; i <= upper; ++i) {
        a[i] += x;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << a[i] << " ";
  }
  return 0;
}