alexjercan/bugnet huggingface dataset:
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);

  rep(i, N) cin >> A.at(i);

  rep(Ki, K) {
    vector<int> B(N + 1);
    rep(i, N) {

      int l = max(0, i - A[i]);
      int r = min(i + A[i] + 1, N);
      B[l]++;
      B[r]--;
    }
    rep(i, N) B[i + 1] += B[i];
    B.pop_back();
    if (A == B)
      break;
    A = B;
  }

  rep(i, N) { cout << A.at(i) << " "; }
  cout << endl;
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  vector<int> B(N + 1);
  rep(i, N) cin >> A.at(i);

  rep(Ki, K) {
    rep(i, N) {
      int l = max(0, i - A[i]);
      int r = min(i + A[i] + 1, N);
      B[l]++;
      B[r]--;
    }
    rep(i, N) B[i + 1] += B[i];
    B.pop_back();
    if (A == B)
      break;
    A = B;
  }

  rep(i, N) { cout << A.at(i) << " "; }
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define ll long long

using namespace std;

long long MOD = 1000000007;

template <typename T> void cout_vec(vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    if (i != 0) {
      cout << ' ';
    }
    cout << vec[i];
  }
  cout << endl;
}

int main() {
  int N, K;
  cin >> N >> K;

  vector<int> vec(N + 1);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }

  for (int i = 0; i < K; i++) {
    vector<int> nw(N + 1, 0);
    for (int j = 0; j < N; j++) {
      nw[max(0, j - vec[j])]++;
      nw[min(N, j + vec[j] + 1)]--;
    }
    ll sum_ = 0;
    for (int k = 0; k < N; k++) {
      nw[k + 1] += nw[k];
      sum_ += (ll)nw[k];
    }
    vec.swap(nw);
    if (sum_ == (ll)N * N) {
      // cout << i << endl;
      break;
    }
    // cout << vec[0] << endl;
  }
  vec.pop_back();
  cout_vec(vec);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define ll long long

using namespace std;

long long MOD = 1000000007;

template <typename T> void cout_vec(vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    if (i != 0) {
      cout << ' ';
    }
    cout << vec[i];
  }
  cout << endl;
}

int main() {
  int N, K;
  cin >> N >> K;

  vector<int> vec(N + 1);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }

  for (int i = 0; i < K; i++) {
    vector<int> nw(N + 1, 0);
    for (int j = 0; j < N; j++) {
      nw[max(0, j - vec[j])]++;
      nw[min(N, j + vec[j] + 1)]--;
    }
    ll sum_ = 0;
    for (int k = 0; k < N; k++) {
      nw[k + 1] += nw[k];
      sum_ += (ll)nw[k];
    }
    vec.swap(nw);
    if (sum_ == (ll)N * K) {
      break;
    }
    // cout << vec[0] << endl;
  }
  vec.pop_back();
  cout_vec(vec);
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N, K;
  cin >> N >> K;

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

  rep(k, K) {
    vector<int> B(N, 0);
    rep(i, N) {
      int l = max(0, i - A[i]);
      int r = min(N - 1, i + A[i]);
      B[l]++;

      if (r + 1 < N) {
        B[r + 1]--;
      }
    }

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

    if (log(N) + 30 < k) {
      break;
    }
  }

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

  cout << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>

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 k = 0; k < K; k++) {
    vector<int> B(N, 0), S(N);
    for (int i = 0; i < N; i++) {
      int min_i = ceil(i - A[i] - 0.5);
      int max_i = floor(i + A[i] + 0.5);
      for (int j = max(min_i, 0); j <= min(max_i, N - 1); j++) {
        B[j]++;
      }
    }

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

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

  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int IINF = INT_MAX;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;

int main() {
  ll n, k;
  cin >> n >> k;
  V<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

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

  for (int i = 0; i < n; i++) {
    if (i != n - 1)
      cout << a[i] << " ";
    else
      cout << a[i] << endl;
  }

  return 0;
}


Error: WA

Fixed submission:

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int IINF = INT_MAX;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;

int main() {
  ll n, k;
  cin >> n >> k;
  V<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

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

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

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
int a[200005] = {0}, b[200005] = {0};
int main() {
  int n, k, l, r, cnt = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  for (int i = 1; i <= k; i++) {
    cnt = 0;
    for (int j = 1; j <= n; j++) {
      if (a[j] == n)
        cnt++;
    }
    if (cnt == n)
      break;
    memset(b, 0, sizeof(b));
    for (int j = 1; j <= n; j++) {
      l = j - a[j];
      r = j + a[j];
      if (l < 1)
        l = 1;
      if (r > n)
        r = n;
      b[l]++;
      if (r + 1 <= n)
        b[r + 1]--;
    }
    for (int j = 2; j <= n; j++) {
      b[j] += b[j - 1];
    }
    for (int j = 1; j <= n; j++) {
      a[j] = b[j];
    }
  }
  for (int i = 1; i <= n; i++) {
    printf("%d ", b[i]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
int a[200005] = {0}, b[200005] = {0};
int main() {
  int n, k, l, r, cnt = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  for (int i = 1; i <= k; i++) {
    cnt = 0;
    for (int j = 1; j <= n; j++) {
      if (a[j] == n)
        cnt++;
    }
    if (cnt == n)
      break;
    memset(b, 0, sizeof(b));
    for (int j = 1; j <= n; j++) {
      l = j - a[j];
      r = j + a[j];
      if (l < 1)
        l = 1;
      if (r > n)
        r = n;
      for (int ii = l; ii <= r; ii++) {
        b[ii]++;
      }
    }
    for (int j = 1; j <= n; j++) {
      a[j] = b[j];
    }
  }
  for (int i = 1; i <= n; i++) {
    printf("%d ", b[i]);
  }
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define INF 2e9
#define rep(i, n, m) for (int i = n; i < m; i++)

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;

  vector<int> a(n), b(n + 1, 0);
  rep(i, 0, n) cin >> a[i];

  if (k > 500)
    k = 500;
  while (k) {
    rep(i, 0, n) {
      b[max(0, i - a[i])]++;
      b[min(n, i + a[i] + 1)]--;
    }
    rep(i, 0, n) {
      b[i + 1] += b[i];
      a[i] = b[i];
      b[i] = 0;
    }
    k--;
  }
  rep(i, 0, n) cout << a[i] << " ";
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define INF 2e9
#define rep(i, n, m) for (int i = n; i < m; i++)

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;

  vector<int> a(n), b(n + 1, 0);
  rep(i, 0, n) cin >> a[i];

  while (k) {
    rep(i, 0, n) {
      b[max(0, i - a[i])]++;
      b[min(n, i + a[i] + 1)]--;
    }
    rep(i, 0, n) {
      b[i + 1] += b[i];
      a[i] = b[i];
      b[i] = 0;
    }
    k--;
  }
  rep(i, 0, n) cout << a[i] << " ";
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define debug(v)                                                               \\
  cout << #v << ":";                                                           \\
  for (auto x : v) {                                                           \\
    cout << x << ' ';                                                          \\
  }                                                                            \\
  cout << endl;
#define INF 1000000000
#define mod 1000000007
using ll = long long;
const ll LINF = 1001002003004005006ll;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);

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

  rep(_, k) {
    if (*min_element(ALL(a)) == n) {
      rep(i, n) cout << n << (i + 1 == n ? "\\n" : " ");
      return 0;
    }

    vector<int> imos(n + 1, 0), b(n);

    rep(i, n) {
      imos[max(0, i - a[i])]++;
      imos[min(n, i + a[i] + 1)]--;
    }

    int p = 0;
    rep(i, n) {
      p += imos[i];
      b[i] = p;
    }
    swap(a, b);
  }
  rep(i, n) cout << a[i] << (i + 1 == n ? "\\n" : " ");
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define debug(v)                                                               \\
  cout << #v << ":";                                                           \\
  for (auto x : v) {                                                           \\
    cout << x << ' ';                                                          \\
  }                                                                            \\
  cout << endl;
#define INF 1000000000
#define mod 1000000007
using ll = long long;
const ll LINF = 1001002003004005006ll;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);

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

  rep(_, k) {
    if (*min_element(ALL(a)) == n) {
      rep(i, n) cout << n << (i + 1 == n ? "\\n" : " ");
      return 0;
    }

    vector<int> imos(n, 0), b(n);

    rep(i, n) {
      imos[max(0, i - a[i])]++;
      imos[min(n, i + a[i] + 1)]--;
    }

    int p = 0;
    rep(i, n) {
      p += imos[i];
      b[i] = p;
    }
    swap(a, b);
  }
  rep(i, n) cout << a[i] << (i + 1 == n ? "\\n" : " ");
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  rep(j, k) {
    vector<int> b(n, 0);
    rep(i, n) {
      int l = max(0, i - a[i]);
      int r = min(n - 1, i + a[i]);
      b[l]++;
      if (r < n - 1)
        b[r + 1]--;
    }
    bool judge = 1;
    rep(i, n) {
      if (i > 0)
        b[i] += b[i - 1];
      a[i] = b[i];
      if (b[i] != n)
        judge = 0;
    }
    if (judge)
      break;
  }
  rep(i, n) cout << a[i] << " ";
}

Error: TLE

Fixed submission:

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n), b(n, 0);
  rep(i, n) cin >> a[i];
  rep(j, k) {
    rep(i, n) {
      int l = i - a[i];
      if (l < 0)
        l = 0;
      int r = i + a[i];
      if (r > n - 1)
        r = n - 1;
      // cout<<l<<" "<<r<<endl;
      for (int f = l; f <= r; f++) {
        b[f]++;
      }
    }
    rep(i, n) {
      a[i] = b[i];
      b[i] = 0;
    }
    if (n * n == accumulate(all(a), 0))
      break;
  }
  rep(i, n) cout << a[i] << " ";
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N, M, H, W, Q, K, A, B;
string S;
const ll MOD = 998244353;
// const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL << 62);

int main() {
  cin >> N >> K;
  vec a(N);
  rep(i, N) cin >> a[i];
  // rep(i,N) a[i] = 0;
  rep(_, K) {
    vec bit(N + 2, 0);
    rep(i, N) {
      bit[max(1LL, (i + 1) - a[i])] += 1;
      bit[min(N + 1, (i + 1) + a[i] + 1)] += -1;
    }
    ll m = N;
    reps(i, 1, N + 2) bit[i] += bit[i - 1];
    rep(i, N) {
      a[i] = bit[i + 1];
      m = min(m, a[i]);
    }
    if (m == N) {
      break;
    }
  }
  rep(i, N) { cout << a[i] << " \\n"[i == N - 1]; }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N, M, H, W, Q, K, A, B;
string S;
const ll MOD = 998244353;
// const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL << 62);

int main() {
  class BIT {
    ll n;
    unordered_map<ll, ll> bitree;

  public:
    BIT(unsigned long _n) { n = _n; }
    void add(ll id, ll x) {
      while (id <= n) {
        bitree[id] += x;
        id += id & -id;
      }
      return;
    }
    ll sum(ll id) {
      ll temp = 0;
      while (id > 0) {
        temp += bitree[id];
        id -= id & -id;
      }
      return temp;
    }
  };
  cin >> N >> K;
  vec a(N);
  rep(i, N) cin >> a[i];
  rep(_, K) {
    BIT bit(N + 2);
    rep(i, N) {
      bit.add(max(1LL, (i + 1) - a[i]), 1);
      bit.add(min(N + 1, (i + 1) + a[i] + 1), -1);
    }
    rep(i, N) a[i] = bit.sum(i + 1);
    if (*min_element(ALL(a)) == N)
      break;
  }
  rep(i, N) { cout << a[i] << " \\n"[i == N - 1]; }
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

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

const int MX = 200005;
int a[MX], b[MX];

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  bool flag = true;
  while (flag && k--) {
    for (int i = 1; i <= n; i++) {
      b[max(1, i - a[i])]++;
      b[min(n + 1, i + a[i] + 1)]--;
    }
    flag = false;
    for (int i = 1; i <= n; i++) {
      b[i] += b[i - 1];
      if (a[i] != b[i])
        a[i] = b[i], flag = true;
    }
    for (int i = 1; i <= n; i++)
      b[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    if (i > 1)
      printf(" ");
    printf("%d", a[i]);
  }
  printf("\\n");
  return 0;
}

Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

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

const int MX = 200005;
int a[MX], b[MX];

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  while (k--) {
    for (int i = 1; i <= n; i++) {
      b[(i - a[i] < 1) ? 1 : (i - a[i])]++;
      b[(i + a[i] + 1 > n) ? (n + 1) : (i + a[i] + 1)]--;
    }
    for (int i = 1; i <= n; i++)
      a[i] = b[i] += b[i - 1];
    for (int i = 1; i <= n; i++)
      b[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    if (i > 1)
      printf(" ");
    printf("%d", a[i]);
  }
  printf("\\n");
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

/**
 *    created: 13.06.2020 21:27:52
 **/

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }
  // k = min(k, 2 + (int)log2(n));
  for (int l = 1; l <= k; l++) {
    vector<int> b(n + 1);
    rep(i, n) {
      b[min(i + a[i] + 1, n)]--;
      b[max(0, i - a[i])]++;
    }
    for (int i = 0; i < n; i++) {
      b[i + 1] += b[i];
    }
    b.pop_back();
    if (a == b)
      break;
    rep(i, n) a[i] = b[i];
  }
  rep(i, n) cout << a[i] << " ";
  cout << endl;
}
/*
int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i,N)cin >> A[i];
    rep(t, K)
    {
        vector<int> imos(N + 1);
        rep(i, N)
        {
            imos[max(i - A[i], 0)]++;
            imos[min(i + A[i] + 1, N)]--;
        }
        rep(i, N) imos[i + 1] += imos[i];
        imos.pop_back();
        if (A == imos) break;
        A = imos;
    }
    rep(i, N) cout << A[i] << ' ';
    cout << '\\n';
}*/

Error: WA

Fixed submission:

/**
 *    created: 13.06.2020 21:27:52
 **/

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }
  // k = min(k, 2 + (int)log2(n));
  for (int l = 1; l <= k; l++) {
    vector<int> b(n);
    rep(i, n) {
      b[min(i + a[i] + 1, n)]--;
      b[max(0, i - a[i])]++;
    }
    bool ok = 1;
    for (int i = 0; i < n - 1; i++) {
      b[i + 1] += b[i];
      ok &= (b[i] == n);
    }

    if (a == b)
      break;
    rep(i, n) a[i] = b[i];
  }
  rep(i, n) cout << a[i] << " ";
  cout << endl;
}
/*
int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i,N)cin >> A[i];
    rep(t, K)
    {
        vector<int> imos(N + 1);
        rep(i, N)
        {
            imos[max(i - A[i], 0)]++;
            imos[min(i + A[i] + 1, N)]--;
        }
        rep(i, N) imos[i + 1] += imos[i];
        imos.pop_back();
        if (A == imos) break;
        A = imos;
    }
    rep(i, N) cout << A[i] << ' ';
    cout << '\\n';
}*/
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using ULL = unsigned long long;
using LL = long long;
using String = std::string;
using Ints = std::vector<int>;
using Doubles = std::vector<double>;
using Bools = std::vector<bool>;
using Strings = std::vector<std::string>;
using ULLs = std::vector<ULL>;
using LLs = std::vector<LL>;

// pythonのdictionary相当
template <typename T1, typename T2> using Dict = std::unordered_map<T1, T2>;

int main(void) {
  int n, k;
  std::cin >> n >> k;
  Ints A(n);
  for (int i = 0; i < n; i++) {
    int _a;
    std::cin >> _a;
    A[i] = _a;
  }

  for (int i = 0; i < std::min(50, k); i++) {
    Ints B(n + 1, 0);
    for (int j = 0; j < n; j++) {
      B[std::max(0, j - A[j])]++;
      B[std::min(n, j + A[j] + 1)]--;
    }
    for (int j = 0; j < n; j++) {
      B[j + 1] += B[j];
    }
    A = B;
  }

  for (int i = 0; i < n; i++) {
    std::cout << A[i] << " ";
  }
  std::cout << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using ULL = unsigned long long;
using LL = long long;
using String = std::string;
using Ints = std::vector<int>;
using Doubles = std::vector<double>;
using Bools = std::vector<bool>;
using Strings = std::vector<std::string>;
using ULLs = std::vector<ULL>;
using LLs = std::vector<LL>;

// pythonのdictionary相当
template <typename T1, typename T2> using Dict = std::unordered_map<T1, T2>;

int main(void) {
  int n, k;
  std::cin >> n >> k;
  Ints A(n);
  for (int i = 0; i < n; i++) {
    int _a;
    std::cin >> _a;
    A[i] = _a;
  }

  for (int i = 0; i < k; i++) {
    Ints B(n + 1, 0);
    for (int j = 0; j < n; j++) {
      B[std::max(0, j - A[j])]++;
      B[std::min(n, j + A[j] + 1)]--;
    }
    for (int j = 0; j < n; j++) {
      B[j + 1] += B[j];
    }
    A = B;
  }

  for (int i = 0; i < n; i++) {
    std::cout << A[i] << " ";
  }
  std::cout << std::endl;

  return 0;
}