alexjercan/bugnet huggingface dataset:
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> intensity(n);

  for (int i = 0; i < n; i++) {
    cin >> intensity[i];
  }
  for (int j = 0; j < min(k, 50); j++) {
    vector<int> power(n + 1);
    for (int i = 0; i < n; i++) {
      int start = i - intensity[i];
      int end = i + intensity[i] + 1;
      if (start < 0)
        start = 0;
      if (end >= n)
        end = n;
      power[start] += 1;
      power[end] -= 1;
    }

    long long current = 0;
    for (int i = 0; i < n; i++) {
      current += power[i];
      intensity[i] = current;
    }
  }
  for (int x : intensity) {
    cout << x << " ";
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> intensity(n);

  for (int i = 0; i < n; i++) {
    cin >> intensity[i];
  }
  for (int j = 0; j < k; j++) {
    vector<int> power(n + 1);
    for (int i = 0; i < n; i++) {
      int start = i - intensity[i];
      int end = i + intensity[i] + 1;
      if (start < 0)
        start = 0;
      if (end >= n)
        end = n;
      power[start] += 1;
      power[end] -= 1;
    }

    long long current = 0;
    for (int i = 0; i < n; i++) {
      current += power[i];
      intensity[i] = current;
    }
  }
  for (int x : intensity) {
    cout << x << " ";
  }
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N), B(N, 0);
  rep(i, N) cin >> A[i];

  rep(k, K) {
    // B_iの計算
    rep(i, N) B[i] = 0;
    rep(i, N) {
      int l_min = max(i - A[i], 0);
      int l_max = min(i + A[i], N - 1);
      // for (int j=l_min;j<=l_max;++j) B[j]++;
      B[l_min]++;
      if (l_max < N - 1)
        B[l_max + 1]--;
    }
    for (int i = 1; i < N; i++)
      B[i] += B[i - 1];

    // A_iをB_iに更新
    rep(i, N) A[i] = B[i];

    // 出力
    /*
    printf("%2d: ", k+1);
    rep(i,N) printf("%2d ", A[i]);
    printf("\\n");
    */

    // 収束判定
    bool conv = true;
    rep(i, N) if (A[i] != N) conv = false;
    if (conv)
      break;
  }

  rep(i, N) printf("%d ", A[i]);

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N), B(N, 0);
  rep(i, N) cin >> A[i];

  rep(k, K) {
    // B_iの計算
    rep(i, N) B[i] = 0;
    rep(i, N) {
      int l_min = max(i - A[i], 0);
      int l_max = min(i + A[i], N - 1);
      for (int j = l_min; j <= l_max; ++j)
        B[j]++;
    }

    // A_iをB_iに更新
    rep(i, N) A[i] = B[i];

    // 出力
    /*
    printf("%2d: ", k+1);
    rep(i,N) printf("%2d ", A[i]);
    printf("\\n");
    */

    // 収束判定
    bool conv = true;
    rep(i, N) if (A[i] != N) conv = false;
    if (conv)
      break;
  }

  rep(i, N) printf("%d ", A[i]);

  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void solve() {
  int n, m, k, i, j, count = 0, sum = 0, maxi = 0, mini = 1e18, flag = 0;
  cin >> n >> k;

  vector<int> a(n + 1);
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }

  for (i = 1; i <= k; i++) {
    vector<int> freq(n + 1, 0);
    flag = 0;
    for (j = 1; j <= n; j++) {
      int l = max((long long)1, j - a[j]);
      int r = min(n, j + a[j]);
      freq[l]++;
      if (r + 1 <= n)
        freq[r + 1]--;
    }
    for (j = 2; j <= n; j++) {
      freq[j] += freq[j - 1];
    }

    for (j = 1; j <= n; j++) {
      if (freq[j] != n) {
        flag = 1;
        break;
      }
    }

    a = freq;

    if (flag == 0)
      break;
  }

  for (i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}

Error: TLE

Fixed submission:

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

void solve() {
  int n, m, k, i, j, count = 0, sum = 0, maxi = 0, mini = 1e18, flag = 0;
  cin >> n >> k;

  vector<int> a(n + 1);
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }

  for (i = 1; i <= k; i++) {
    vector<int> freq(n + 1, 0);
    for (j = 1; j <= n; j++) {
      int l = max((long long)1, j - a[j]);
      int r = min(n, j + a[j]);
      freq[l]++;
      if (r + 1 <= n)
        freq[r + 1]--;
    }
    for (j = 2; j <= n; j++) {
      freq[j] += freq[j - 1];
    }

    for (j = 1; j <= n; j++) {
      if (freq[j] != n) {
        flag = 1;
        break;
      }
    }

    a = freq;

    if (flag == 0)
      break;
  }

  for (i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}
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 j = 0; j < n; j++)
    cin >> a[j];

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

  for (int i = 0; i < n; i++)
    cout << a[i] << " ";
  cout << endl;
}

Error: WA

Fixed submission:

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

typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  vector<vector<int>> a(n, vector<int>(k + 1, 0));
  for (int j = 0; j < n; j++)
    cin >> a[j][0];

  bool same = true;
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n; j++) {
      for (int h = j - a[j][i]; h <= j + a[j][i]; h++) {
        if (0 <= h && h < n)
          a[h][i + 1]++;
      }
      if (a[j][i] != a[j][i + 1])
        same = false;
    }
    if (same)
      break;
  }

  for (int j = 0; j < n; j++)
    cout << a[j][k] << " ";
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
#define mp make_pair
#define fi first
#define se second
#define All(x) (x).begin(), (x).end()
#define Y1 "YES"
#define N1 "NO"
#define ENDL '\\n'
#define count2(x) _builtin_popcount(x)
int num[300000];
int ans[300000];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; ++i)
    cin >> ans[i];
  for (int i = 0; i < k; ++i) {
    int pass = 1;
    for (int j = 1; j <= n; ++j)
      num[j] = 0;
    for (int j = 1; j <= n; ++j) {
      if (j - ans[j] <= 1)
        num[1]++;
      else
        ++num[j - ans[j]];
      if (j + ans[j] <= n)
        num[j + ans[j] + 1]--;
    }
    int sum = 0;
    for (int j = 1; j <= n; ++j) {
      sum += num[j];
      ans[j] = sum;
      if (sum != n)
        pass = 0;
    }
    if (pass)
      break;
  }
  for (int i = 1; i <= n; ++i)
    cout << ans[i] << " ";
  return 0;
}
/*
4 1
0 0 0 0
1 1 1 1
4 1
1 0 0 0
1 2 1 1
4 1
4 0 0 0
1 2 2 2
*/


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
#define mp make_pair
#define fi first
#define se second
#define All(x) (x).begin(), (x).end()
#define Y1 "YES"
#define N1 "NO"
#define ENDL '\\n'
#define count2(x) _builtin_popcount(x)
int num[300000];
int ans[300000][2];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; ++i)
    cin >> ans[i][0];
  for (int i = 0; i < k; ++i) {
    int pass = 1;
    for (int j = 1; j <= n; ++j)
      ans[j][(i + 1) % 2] = 0;
    for (int j = 1; j <= n; ++j) {
      int d = ans[j][i % 2];
      for (int p = 0; p <= d && p + j <= n; ++p) {
        ans[p + j][(i + 1) % 2]++;
      }
      for (int p = 1; p <= d && j - p >= 1; ++p) {
        ans[j - p][(i + 1) % 2]++;
      }
    }
    for (int j = 1; j <= n; ++j)
      if (ans[j][(i + 1) % 2] != n) {
        pass = 0;
        break;
      }
    if (pass || i == k - 1) {
      for (int j = 1; j <= n; ++j)
        cout << ans[j][(i + 1) % 2] << " ";
      return 0;
    }
  }
  return 0;
}
/*
4 1
0 0 0 0
1 1 1 1
4 1
1 0 0 0
1 2 1 1
4 1
4 0 0 0
1 2 2 2
*/
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int x[200010], s[200010];
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  for (int i = 1; i <= a; i++)
    scanf("%d", &x[i]);

  for (int j = 1; j <= 50 && j <= b; j++) {
    for (int i = 1; i <= a; i++) {
      int L = i - x[i];
      int R = i + x[i];
      if (L < 1)
        L = 1;
      if (R > a)
        R = a;
      s[L]++, s[R + 1]--;
    }

    for (int i = 1; i <= a; i++)
      x[i] = x[i - 1] + s[i];
    for (int i = 1; i <= a + 1; i++)
      s[i] = 0;
  }
  for (int i = 1; i <= a; i++)
    printf("%d ", x[i]);
}

Error: WA

Fixed submission:

#include <stdio.h>

int x[200010], s[200010];
int main() {
  freopen("input.txt", "r", stdin);
  int a, b;
  scanf("%d%d", &a, &b);
  for (int i = 1; i <= a; i++)
    scanf("%d", &x[i]);

  for (int j = 1; j <= 50 && j <= b; j++) {
    for (int i = 1; i <= a; i++) {
      int L = i - x[i];
      int R = i + x[i];
      if (L < 1)
        L = 1;
      if (R > a)
        R = a;
      s[L]++, s[R + 1]--;
    }

    for (int i = 1; i <= a; i++)
      x[i] = x[i - 1] + s[i];
    for (int i = 1; i <= a + 1; i++)
      s[i] = 0;
  }
  for (int i = 1; i <= a; i++)
    printf("%d ", x[i]);
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  int N, K;
  cin >> N >> K;
  int A[N];
  for (int i = 0; i < N; i++)
    cin >> A[i];
  int B[N + 1];

  int count = 0;
  while (count < K) {
    for (int i = 0; i < N; i++)
      B[i] = 0;

    for (int i = 0; i < N; i++) {
      int xmin = max(i - A[i], 0);
      int xmax = min(i + A[i] + 1, N);
      B[xmin]++;
      B[xmax]--;
    }

    for (int i = 0; i < N; i++) {
      B[i + 1] += B[i];
    }

    int tot = 0;
    for (int i = 0; i < N; i++) {
      A[i] = B[i];
      tot += A[i];
    }
    if (tot == N * N)
      break;

    count++;
  }

  for (int i = 0; i < N; i++)
    cout << A[i] << " ";
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;
  int A[N];
  for (int i = 0; i < N; i++)
    cin >> A[i];
  int xmin[N];
  int xmax[N];

  int count = 0;
  while (count < K) {
    /*
    for (int i = 0; i < N; i++) expo[i] = 0;

    for (int i = 0; i < N; i++) {
            int xmin = i - A[i];
            int xmax = i + A[i];
            for (int j = xmin; j <= xmax; j++) {
                    expo[j] += 1;
            }
    }

    for (int i = 0; i < N; i++) {
            A[i] = expo[i];
    }
    */

    for (int i = 0; i < N; i++) {
      xmin[i] = i - A[i];
      xmax[i] = i + A[i];
    }
    for (int i = 0; i < N; i++)
      A[i] = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if ((xmin[j] <= i) && (i <= xmax[j]))
          A[i]++;
      }
    }
    count++;
  }

  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>
#include <string.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1001001001;

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

  rep(i, k) {
    vector<ll> memo(n + 1);
    rep(j, n) {
      int l = j - a[j];
      int r = j + a[j] + 1;
      if (l < 0)
        l = 0;
      if (r >= n)
        r = n;

      memo[l]++;
      memo[r]--;
    }
    rep(j, n) memo[j + 1] += memo[j];
    memo.pop_back();
    if (a == memo)
      break;
    a = memo;
  }

  rep(i, n) cout << a[i] << " ";
  cout << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <string.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1001001001;

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

  rep(i, k) {
    vector<ll> memo(n);
    rep(j, n) {
      int l = j - a[j];
      int r = j + a[j];
      if (l < 0)
        l = 0;
      if (r >= n)
        r = n - 1;

      rep(x, r - l + 1) memo[x + l]++;
    }
    a = memo;
  }

  rep(i, n) cout << a[i] << " ";
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int a[(uint)2e5];
int a2[(uint)2e5];
int main() {
  int n, k;
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  rep(j, k) {
    rep(i, n) {
      a2[max(0, i - a[i])]++;
      if (i + a[i] + 1 < n)
        a2[i + a[i] + 1]--;
    }
    bool comp = true;
    for (int i = 1; i < n; i++) {
      a2[i] += a2[i - 1];
      if (a2[i] != n)
        comp = false;
    }
    memcpy(a, a2, sizeof(int) * n);
    memset(a2, 0, sizeof(int) * n);
    if (comp)
      break;
  }
  rep(i, n) cout << a[i] << " ";
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int a[(unsigned int)2e5];
int a2[(unsigned int)2e5];
int main() {
  int n, k;
  cin >> n >> k;
  rep(i, n) { cin >> a[i]; }
  rep(j, k) {
    rep(i, n) {
      a2[i]++;
      for (int l = 1; l <= a[i]; l++) {
        if (i - l >= 0)
          a2[i - l]++;
        if (i + l < n)
          a2[i + l]++;
      }
    }
    memcpy(a, a2, sizeof(int) * n);
    memset(a2, 0, sizeof(int) * n);
    // rep(i, n) cout << a[i] << " ";
    // cout << endl;
    bool comp = true;
    rep(i, n) if (a[i] != n) comp = false;
    if (comp)
      break;
  }
  rep(i, n) cout << a[i] << " ";
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;
typedef long long ll;
const int N = 2e5 + 10;

ll a[N];
ll c[N];

int main() {
  //	freopen("in.txt","r",stdin);
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  if (k >= n) {
    for (int i = 1; i <= n; i++)
      printf("%d ", n);
    return 0;
  }
  bool f = false;
  while (!f && k--) {
    int cnt = 0;
    for (int i = 0; i <= n; i++)
      c[i] = 0;
    for (int i = 1; i <= n; i++) {
      int l = max(1ll, i - a[i]);
      int r = min(1ll * n, i + a[i]);
      c[l]++;
      c[r + 1]--;
    }
    for (int i = 1; i <= n; i++)
      c[i] += c[i - 1];
    for (int i = 1; i <= n; i++) {
      a[i] = c[i];
      if (a[i] == n)
        cnt++;
    }
    if (cnt == n)
      f = true;
  }
  for (int i = 1; i <= n; i++)
    printf("%d ", a[i]);

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;
typedef long long ll;
const int N = 2e5 + 10;

ll a[N];
ll c[N];

int main() {
  // freopen("in.txt","r",stdin);
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  if (k >= n) {
    for (int i = 1; i <= n; i++)
      printf("%d ", n);
    return 0;
  }
  bool f = false;
  while (!f && k--) {
    int cnt = 0;
    for (int i = 0; i <= n; i++)
      c[i] = 0;
    for (int i = 1; i <= n; i++) {
      int l = max(1ll, i - a[i]);
      int r = min(1ll * n, i + a[i]);
      c[l]++;
      c[r + 1]--;
    }
    for (int i = 1; i <= n; i++)
      c[i] += c[i - 1];
    for (int i = 1; i <= n; i++) {
      a[i] = c[i];
      if (a[i] == n)
        cnt++;
    }
    if (cnt == n)
      f = false;
  }
  for (int i = 1; i <= n; i++)
    printf("%d ", a[i]);

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

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

const int MAXN = 2e5 + 10;

int N, K;
int A[MAXN];

int sum[MAXN];
int n_count = 0;

void do_operation() {
  int cost = 0;
  for (int i = 1; i <= N; ++i)
    sum[i] = 0;
  for (int i = 1; i <= N; ++i) {
    sum[max(1, i - A[i])]++;
    sum[min(N + 1, i + A[i] + 1)]--;
  }
  n_count = 0;
  for (int i = 1; i <= N; ++i) {
    cost += sum[i];
    A[i] = cost;
    if (cost == N)
      ++n_count;
  }
}

void solve() {
  for (int i = 1; i <= N; ++i)
    if (A[i] == N)
      n_count += 1;
  for (int k = 1; k <= K; ++k) {
    if (n_count == N)
      break;
    do_operation();
  }
}

int main() {
  scanf("%d %d", &N, &K);
  for (int i = 1; i <= N; ++i)
    scanf("%d", &A[i]);
  solve();
  for (int i = 1; i <= N; ++i)
    printf("%d ", A[i]);
  printf("\\n");
  return 0;
}

Error: WA

Fixed submission:

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

const int MAXN = 1e5 + 10;

int N, K;
int A[MAXN];

int sum[MAXN];
int n_count = 0;

void do_operation() {
  int cost = 0;
  for (int i = 1; i <= N; ++i)
    sum[i] = 0;
  for (int i = 1; i <= N; ++i) {
    sum[max(1, i - A[i])]++;
    sum[min(N + 1, i + A[i] + 1)]--;
  }
  n_count = 0;
  for (int i = 1; i <= N; ++i) {
    cost += sum[i];
    A[i] = cost;
    if (cost == N)
      ++n_count;
  }
}

void solve() {
  for (int i = 1; i <= N; ++i)
    if (A[i] == N)
      n_count += 1;
  for (int k = 1; k <= K; ++k) {
    if (n_count == N)
      break;
    do_operation();
  }
}

int main() {
  scanf("%d %d", &N, &K);
  for (int i = 1; i <= N; ++i)
    scanf("%d", &A[i]);
  solve();
  for (int i = 1; i <= N; ++i)
    printf("%d ", A[i]);
  printf("\\n");
  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, 0);
  vector<int> B(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

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

  while (K) {
    for (int i = 0; i < N; i++) {
      B[i] = 0;
    }
    for (int i = 0; i < N; i++) {
      int left = max(0, i - A[i]);
      int right = min(N, i + A[i]);
      B[left]++;
      if (right + 1 < N) {
        B[right + 1]--;
      }
    }
    for (int i = 1; i < N; i++) {
      B[i] += B[i - 1];
    }
    for (int i = 0; i < N; i++) {
      A[i] = B[i];
    }
    K--;
  }

  for (int i = 0; i < N - 1; i++) {
    cout << A[i] << " ";
  }
  cout << A[N - 1] << endl;
  return 0;
}


Error: -6
double free or corruption (out)


Fixed submission:

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N, 0);
  vector<int> B(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  if (K > 30) {
    for (int i = 0; i < N - 1; i++) {
      cout << N << " ";
    }
    cout << N << endl;
    return 0;
  }
  int cnt = 0;
  while (K) {
    cnt = 0;
    for (int i = 0; i < N; i++) {
      if (A[i] >= N - 1) {
        cnt++;
        continue;
      }

      for (int j = min(0, i - A[i]); j <= max(N - 1, i + A[i]); j++) {
        B[j]++;
      }
    }
    for (int k = 0; k < N; k++) {
      B[k] += cnt;
      if (B[k] > N)
        B[k] = N;
      A[k] = B[k];
      B[k] = 0;
    }

    K--;

    /*for(int p=0;p<N-1;p++){
      cout<<A[p]<<" ";
    }
    cout<<A[N-1]<<endl;*/
  }

  for (int p = 0; p < N - 1; p++) {
    if (A[p] >= N) {
      cout << N << " ";
    } else
      cout << A[p] << " ";
  }
  if (A[N - 1] > N) {
    cout << N << endl;
  } else
    cout << A[N - 1] << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define N 200005
#define inf 1000000009
#define ll long long
#define pii pair<int, int>
#define sz(a) int(a.size())
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int n, k, a[N];
int b = 1;
int in[N];

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  while (b == 1 and k) {
    memset(in, 0, sizeof(in));
    for (int i = 1; i <= n; i++) {
      int l = max(1, i - a[i]);
      int r = min(n, i + a[i]);
      in[l]++;
      in[r + 1]--;
    }
    b = 0;
    for (int i = 1; i <= n; i++) {
      in[i] += in[i - 1];
      a[i] = in[i];
      if (a[i] != n)
        b = 1;
    }
    k--;
  }
  for (int i = 1; i <= n; i++)
    printf("%d ", a[i]);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define N 200005
#define inf 1000000009
#define ll long long
#define pii pair<int, int>
#define sz(a) int(a.size())
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int n, k, a[N];
int b = 1;
int cep[N], sag[N];

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  while (b == 1 and k) {
    memset(cep, 0, sizeof(cep));
    memset(sag, 0, sizeof(sag));
    for (int i = 1; i <= n; i++) {
      cep[max(0, i - a[i] - 1)]--;
      cep[i - 1]++;
      sag[i + 1]++;
      sag[min(n + 1, i + a[i] + 1)]--;
    }
    b = 0;
    for (int i = n; i >= 1; i--)
      cep[i] += cep[i + 1];
    for (int i = 1; i <= n; i++) {
      sag[i] += sag[i - 1];
      a[i] = cep[i] + sag[i] + 1;
      if (a[i] != n - 1)
        b = 1;
    }
    k--;
  }
  for (int i = 1; i <= n; i++)
    printf("%d ", a[i]);
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007; // 998244353;
int dp[400][200001];
void solve() {
  int n, k;
  cin >> n >> k;
  rep(i, n) cin >> dp[0][i];
  int j = 0;
  while (k--) {
    rep(i, n) {
      dp[j + 1][max(i - dp[j][i], 0)]++;
      dp[j + 1][min(i + dp[j][i] + 1, n)]--;
    }
    rep(i, n) { dp[j + 1][i + 1] += dp[j + 1][i]; }
    j++;
    if (dp[j][0] == n && dp[j][n - 1] == n)
      break;
  }
  rep(i, n) cout << dp[j][i] << " ";
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007; // 998244353;
int dp[200001][500];
void solve() {
  int n, k;
  cin >> n >> k;
  rep(i, n) cin >> dp[0][i];
  int j = 0;
  while (k--) {
    rep(i, n) {
      dp[j + 1][max(i - dp[j][i], 0)]++;
      dp[j + 1][min(i + dp[j][i] + 1, n)]--;
    }
    rep(i, n) { dp[j + 1][i + 1] += dp[j + 1][i]; }
    j++;
    if (dp[j][0] == n && dp[j][n - 1] == n)
      break;
  }
  rep(i, n) cout << dp[j][i] << " ";
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}