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

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

const vector<int> Update(const int N, const vector<int> &as) {
  vector<int> updated(N, 0);
  vector<int> diffs(N + 1, 0);
  for (int i = 0; i < N; ++i) {
    int ai = as[i];
    ++diffs[max(0, i - ai)];
    --diffs[min(N, i + ai + 1)];
  }
  int sum = 0;
  for (int i = 0; i < N; ++i) {
    sum += diffs[i];
    updated[i] = sum;
  }
  return updated;
}

const bool IsAll(const int N, const vector<int> &as) {
  return count(as.begin(), as.end(), N) == N;
}

int main() {
  // 単純にシミュレーション
  // K~20回程度で全体が照らされるようになる
  int N, K;
  cin >> N >> K;
  vector<int> as(N);
  for (auto &ai : as)
    cin >> ai;
  for (int i = 0; i < K; ++i) {
    as = Update(N, as);
    if (IsAll(N, as))
      break;
  }
  for (int i = 0; i < N - 1; ++i)
    cout << as[i] << ' ';
  cout << as.back() << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

const vector<int> Update(const int N, const vector<int> &as) {
  vector<int> updated(N, 0);
  for (int i = 0; i < N; ++i) {
    int ai = as[i];
    for (int j = max(0, i - ai); j <= min(N - 1, i + ai); ++j) {
      ++updated[j];
    }
  }
  return updated;
}

const bool IsAll(const int N, const vector<int> &as) {
  return count(as.begin(), as.end(), N) == N;
}

int main() {
  // 単純にシミュレーション
  // K~20回程度で全体が照らされるようになる
  int N, K;
  cin >> N >> K;
  vector<int> as(N);
  for (auto &ai : as)
    cin >> ai;
  for (int i = 0; i < K; ++i) {
    as = Update(N, as);
    if (IsAll(N, as))
      break;
  }
  for (int i = 0; i < N - 1; ++i)
    cout << as[i] << ' ';
  cout << as.back() << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1001001001;
vector<pair<int64_t, int64_t>> func(int64_t x) {
  vector<pair<int64_t, int64_t>> p;
  for (int64_t i = 2; i * i <= x; i++) {
    int cnt = 0;
    if (x % i == 0) {
      while (x % i == 0) {
        cnt++;
        x /= i;
      }
      p.push_back(make_pair(i, cnt));
    }
  }
  if (x != 1) {
    p.push_back(make_pair(x, 1));
  }
  return p;
}

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 < K; i++) {
    vector<int> B(N + 1);
    for (int j = 0; j < N; j++) {
      int l = max(0, j - A[j]);
      int r = min(N, j + A[j] + 1);
      B[l]++;
      B[r]--;
    }
    for (int k = 0; k < N; k++) {
      B[k + 1] += B[k];
    }
    B.pop_back();
    if (A == B) {
      break;
    }
    A = B;
  }
  for (int i = 0; i < N; i++) {
    cout << A[i] << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1001001001;
vector<pair<int64_t, int64_t>> func(int64_t x) {
  vector<pair<int64_t, int64_t>> p;
  for (int64_t i = 2; i * i <= x; i++) {
    int cnt = 0;
    if (x % i == 0) {
      while (x % i == 0) {
        cnt++;
        x /= i;
      }
      p.push_back(make_pair(i, cnt));
    }
  }
  if (x != 1) {
    p.push_back(make_pair(x, 1));
  }
  return p;
}

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

  for (int i = 0; i < K; i++) {
    vector<int> B(N + 1);
    for (int j = 0; j < N; j++) {
      int l = max(0, j - A[j]);
      int r = min(N, j + A[j] + 1);
      B[l]++;
      B[r]--;
    }
    for (int k = 0; k < N; k++) {
      B[k + 1] += B[k];
    }
    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 <cstdio>
#include <iostream>
#define re register
using namespace std;
inline int read() {
  re int t = 0;
  re char v = getchar();
  while (v < '0')
    v = getchar();
  while (v >= '0')
    t = (t << 3) + (t << 1) + v - 48, v = getchar();
  return t;
}
int n, a[200002], b[200002], k, c[200002];
inline void add(re int x, re int y) {
  for (; x <= n; x += x & (-x))
    c[x] += y;
}
inline int ask(re int x) {
  re int sum = 0;
  for (; x; x -= x & (-x))
    sum += c[x];
  return sum;
}
signed main() {
  // freopen("a.in","r",stdin);
  n = read();
  k = read();
  for (re int i = 1; i <= n; ++i)
    a[i] = read();
  for (re int j = 1; j <= k; ++j) {
    for (re int ii = 1; ii <= n; ++ii)
      add(max(1, ii - a[ii]), 1), add(min(n, ii + a[ii]) + 1, -1);
    re int xx = 1;
    for (re int ii = 1; ii <= n; ++ii) {
      a[ii] = ask(ii);
      ;
      if (a[ii] != n)
        xx = 0;
    }
    for (re int ii = 1; ii <= n; ++ii)
      c[ii] = 0;
    if (xx) {
      break;
    }
  }
  for (re int i = 1; i <= n; ++i)
    printf("%d ", a[i]);
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#define re register
using namespace std;
inline int read() {
  re int t = 0;
  re char v = getchar();
  while (v < '0')
    v = getchar();
  while (v >= '0')
    t = (t << 3) + (t << 1) + v - 48, v = getchar();
  return t;
}
int n, a[200002], b[200002], k;
signed main() {
  n = read();
  k = read();
  for (re int i = 1; i <= n; ++i)
    a[i] = read();
  for (re int j = 1; j <= k; ++j) {
    for (re int ii = 1; ii <= n; ++ii) {
      for (re int jj = max(1, ii - a[ii]); jj <= min(n, ii + a[ii]); ++jj)
        ++b[jj];
    }
    re int xx = 1;
    for (re int ii = 1; ii <= n; ++ii) {
      a[ii] = b[ii];
      if (b[ii] != n)
        xx = 0;
      b[ii] = 0;
    }
    if (xx) {
      break;
    }
  }
  for (re int i = 1; i <= n; ++i)
    printf("%d ", a[i]);
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

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

  for (int loop_cnt = 0; loop_cnt < k; loop_cnt++) {
    if (*min_element(a.begin(), a.end()) >= n) {
      break;
    }

    auto imos = vector<int>(n + 1);
    for (int i = 0; i < n; i++) {
      imos[max(0, i - a[i])] += 1;
      imos[min(n, i + a[i] + 1)] -= 1;
    }

    a[0] = imos[0];
    for (int i = 1; i < n; i++) {
      a[i] = a[i - 1] + imos[i];
    }
  }

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

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

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

  auto lamps = vector<long long>(n);
  for (int i = 0; i < n; i++) {
    cin >> lamps[i];
  }

  for (int loop_cnt = 0; loop_cnt < k; loop_cnt++) {
    bool f = true;
    for (int i = 0; i < n; i++) {
      if (lamps[i] < n) {
        f = false;
        break;
      }
    }
    if (f) {
      break;
    }

    auto new_lamps = vector<long long>(n, 0);

    for (int i = 0; i < n; i++) {
      int l = i - lamps[i];
      if (l < 0) {
        l = 0;
      }
      int r = i + lamps[i] + 1;
      if (r > n) {
        r = n;
      }

      for (int j = l; j < r; j++) {
        new_lamps[j]++;
      }
    }

    lamps = new_lamps;
  }

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

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

#include <algorithm>
#include <array>
#include <iostream>
#include <set>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll N, K;
  array<ll, 200001> A[2];

  cin >> N >> K;
  for (ll j = 1; j <= N; j++)
    cin >> A[0][j];

  for (ll k = 1; k <= min(42LL, K); k++) {
    for (ll i = 1; i <= N; i++)
      A[k % 2][i] = 0;
    for (ll i = 1; i <= N; i++) {
      ll d = A[(k + 1) % 2][i];
      A[k % 2][max(1LL, i - d)]++;
      if (i + d + 1 <= N)
        A[k % 2][i + d + 1]--;
    }
    for (ll i = 1; i < N; i++)
      A[k % 2][i + 1] += A[k % 2][i];
  }

  for (ll i = 1; i <= N; i++) {
    cout << (i == 1 ? "" : " ") << A[K % 2][i];
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <iostream>
#include <set>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll N, K;
  array<ll, 200001> A[2];

  cin >> N >> K;
  for (ll j = 1; j <= N; j++) {
    cin >> A[0][j];
  }

  for (ll k = 1; k <= K; k++) {
    bool fin = true;
    for (ll i = 1; i <= N; i++)
      A[k % 2][i] = 0;
    for (ll i = 1; i <= N; i++) {
      ll d = A[(k + 1) % 2][i];
      if (d != N)
        fin = false;
      for (ll j = max(1LL, i - d); j <= min(N, i + d); j++)
        A[k % 2][j]++;
    }
    if (fin)
      break;
  }

  for (ll i = 1; i <= N; i++) {
    cout << (i == 1 ? "" : " ") << A[K % 2][i];
  }
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

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

#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define point pair<int, int>

int N, K;
int mem[200010];

signed main() {
  cin >> N >> K;
  rep(i, N) cin >> mem[i];
  rep(j, min(K, 100LL)) {
    int tmp[400010] = {0};
    rep(i, N) {
      tmp[max(i - mem[i], 0LL)]++;
      tmp[i + mem[i] + 1]--;
    }
    rep(i, N) if (i) tmp[i] += tmp[i - 1];

    rep(i, N) mem[i] = tmp[i];
  }

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

  return 0;
}


Error: 0

Fixed submission:

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

#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define point pair<int, int>

int N, K;
int mem[400010];

signed main() {
  cin >> N >> K;
  rep(i, N) cin >> mem[i];
  rep(j, min(K, 100LL)) {
    int tmp[200010] = {0};
    rep(i, N) {
      tmp[max(i - mem[i], 0LL)]++;
      tmp[i + mem[i] + 1]--;
    }
    rep(i, N) if (i) tmp[i] += tmp[i - 1];

    rep(i, N) mem[i] = tmp[i];
  }

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

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int)x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9 + 7;
const ll INF = 2e18;
template <class T> void print(const T &t) { cout << t << endl; }
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
  ll n, k;
  cin >> n >> k;
  vl a(n + 2);
  a[0] = 0;
  for (ll i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (k >= 10000) {
    for (ll i = 1; i <= n; i++) {
      cout << n << " ";
    }
    cout << endl;
    return 0;
  }
  vl dp(n + 1, 0);
  rep(i, k) {
    for (ll j = 1; j <= n; j++) {
      ll in = j - a[j];
      if (in <= 0)
        in = 1;
      ll out = j + a[j] + 1;
      if (out > n)
        out = n + 1;
      dp[in]++;
      dp[out]--;
    }
    ll count = 0;
    for (ll j = 1; j <= n; j++) {
      count += dp[j];
      a[j] = count;
      dp[j] = 0;
    }
  }
  for (ll i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int)x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9 + 7;
const ll INF = 2e18;
template <class T> void print(const T &t) { cout << t << endl; }
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
  ll n, k;
  cin >> n >> k;
  vl a(n + 2);
  a[0] = 0;
  for (ll i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vl dp(n + 1, 0);
  rep(i, k) {
    for (ll j = 1; j <= n; j++) {
      ll in = j - a[j];
      if (in <= 0)
        in = 1;
      ll out = j + a[j] + 1;
      if (out > n)
        out = n + 1;
      dp[in]++;
      dp[out]--;
    }
    ll count = 0;
    for (ll j = 1; j <= n; j++) {
      count += dp[j];
      a[j] = count;
      dp[j] = 0;
    }
  }
  for (ll i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define PER(i, a, b) for (ll i = (a); i >= (b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a) (a).begin(), (a).end()
const ll INF = 1e18 + 18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const long double pi = 3.141592653589793;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  vector<ll> B(N + 1, 0);
  if (K >= 100) {
    rep(i, N) {
      if (i > 0)
        cout << " ";
      cout << N;
    }
    return 0;
  }
  rep(i, N) {
    cin >> A[i];
    ll mi = max((ll)0, i - A[i]);
    ll ma = min(N - 1, i + A[i]);
    B[mi + 1]++;
    if (ma + 2 <= N)
      B[ma + 2]--;
  }
  rep(i, N) {
    B[i + 1] += B[i];
    A[i] = B[i + 1];
  }
  /*rep(i, N){
  if(i>0)cout<<" ";
  cout<<A[i];
}
  cout<<endl;*/
  rep(j, K - 1) {
    rep(i, N + 1) { B[i] = 0; }
    rep(i, N) {
      ll mi = max((ll)0, i - A[i]);
      ll ma = min(N - 1, i + A[i]);
      B[mi + 1]++;
      if (ma + 2 <= N)
        B[ma + 2]--;
    }
    rep(i, N) {
      B[i + 1] += B[i];
      A[i] = B[i + 1];
    }
    /*rep(i, N){
            if(i>0)cout<<" ";
            cout<<A[i];
    }
    cout<<endl;*/
  }
  rep(i, N) {
    if (i > 0)
      cout << " ";
    cout << A[i];
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define PER(i, a, b) for (ll i = (a); i >= (b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a) (a).begin(), (a).end()
const ll INF = 1e18 + 18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const long double pi = 3.141592653589793;

int main() {
  ll N, K;
  cin >> N >> K;
  if (pow(2, K - 1) >= N) {
    rep(i, N) {
      if (i > 0)
        cout << " ";
      cout << N;
    }
    // return 0;
  }
  vector<ll> A(N);
  vector<vector<ll>> B(K + 1, vector<ll>(N, 0));
  rep(i, N) {
    cin >> A[i];
    B[0][i] = A[i];
  }
  rep(i, K) {
    rep(j, N) {
      ll T = B[i][j];
      ll mi = max((ll)0, j - T);
      ll ma = min(N - 1, j + T);
      for (ll k = mi; k <= ma; k++) {
        B[i + 1][k]++;
      }
    }
    ll Min = INF;
    rep(j, N) {
      // cout<<B[i+1][j]<<" ";
      Min = min(Min, B[i + 1][j]);
    }
    if (Min == N) {
      K = i + 1;
      break;
    }
    // cout<<endl;
  }
  rep(i, N) {
    if (i > 0)
      cout << " ";
    cout << B[K][i];
  }
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, a[200100], i, j, b[200100] = {0}, lo, cnt = 0, f = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < k; i++) {
    for (j = 0; j < n; j++) {
      int l = max((long long)0, j - a[j]);
      int r = min(n - 1, j + a[j]);
      b[l]++;
      if (r + 1 < n)
        b[r + 1]--;
    }
    for (j = 1; j < n; j++)
      b[j] += b[j - 1];
    for (j = 0; j < n; j++) {
      a[j] = b[j];
      if (b[j] == n)
        cnt++;
      b[j] = 0;
      if (cnt == n) {
        f = 1;
        break;
      }
    }
    cnt = 0;
    if (f == 1)
      break;
  }
  for (i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, a[200100], i, j, b[200100] = {0}, lo, cnt = 0, f = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < k; i++) {
    for (j = 0; j < n; j++) {
      int l = max((long long)0, j - a[j]);
      int r = min(n - 1, j + a[j]);
      b[l]++;
      if (r + 1 < n)
        b[r + 1]--;
    }
    for (int j = 1; j < n; j++)
      b[j] += b[j - 1];
    for (j = 0; j < n; j++) {
      a[j] = b[j];
      if (b[j] == n)
        cnt++;
      if (cnt == n) {
        f = 1;
        break;
      }
      cnt = 0;
      b[j] = 0;
    }
    if (f == 1)
      break;
  }
  for (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;
long long n, k, a[200010], b[200010], l[400010], r[400010], ll[200010],
    rr[200010];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  while (k--) {
    int p = 0;
    for (int i = 0; i <= n; i++) {
      b[i] = 0;
      ll[i] = 0;
      rr[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
      l[i] = max(0LL, i - a[i]);
      r[i] = min(n + 1, i + a[i] + 1);
      ll[l[i]]++;
      rr[r[i]]++;
    }
    for (int i = 1; i <= n; i++) {
      ll[i] = ll[i - 1] + ll[i];
      rr[i] = rr[i - 1] + rr[i];
      b[i] = ll[i] - rr[i];
    }
    for (int i = 1; i <= n; i++)
      if (a[i] != b[i])
        p = 233;
    for (int i = 1; i <= n; i++)
      if (a[i] != b[i])
        a[i] = b[i];
    if (p == 0) {
      for (int i = 1; i <= n; i++)
        printf("%lld ", a[i]);
      return 0;
    }
    // for (int i=1;i<=n;i++) printf("%lld %lld ",ll[i],rr[i]);
    // printf("\\n");
    // for (int i=1;i<=n;i++) if (a[i]>hhh||hhh==0) hhh=a[i];
  }
  for (int i = 1; i <= n; i++)
    printf("%lld ", a[i]);
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long n, k, a[200010], b[200010], hhh;
int main() {
  cin >> n >> k;
  hhh = 0;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  while (k--) {
    int p = 0;
    for (int i = 1; i <= n; i++)
      b[i] = 0;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        if (j - i >= 0 && j - i <= a[i] || j - i < 0 && j - i >= -a[i]) {
          b[j]++;
          p = 233;
        }
    for (int i = 1; i <= n; i++)
      a[i] = b[i];
    if (p == 0) {
      for (int i = 1; i <= n; i++)
        printf("%lld ", a[i]);
      return 0;
    }
    // for (int i=1;i<=n;i++) printf("%lld ",a[i]);
    // printf("\\n");
    // for (int i=1;i<=n;i++) if (a[i]>hhh||hhh==0) hhh=a[i];
  }
  for (int i = 1; i <= n; i++)
    printf("%lld ", a[i]);
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;

ll mod(ll a, ll b) {
  ll ret = a % b;
  if (ret < 0)
    ret += b;
  return ret;
}

ll modpow(ll a, ll b, ll c) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = mod(res * a, c);
    a = mod(a * a, c);
    b >>= 1;
  }
  return res;
}

int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  bool h = true;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (k >= 100) {
    for (int i = 0; i < n; i++) {
      cout << n;
      if (i != n - 1) {
        cout << ' ';
      }
    }
    cout << endl;
    return 0;
  }
  for (int i = 0; i < k; i++) {
    int b[n];
    for (int j = 0; j < n; j++) {
      b[j] = 0;
    }
    for (int j = 0; j < n; j++) {
      int m = max(0, j - a[j]);
      int M = min(n - 1, j + a[j]);
      b[m]++;
      if (M < n - 1)
        b[M + 1]--;
    }
    for (int j = 1; j < n; j++)
      b[j] += b[j - 1];
    for (int j = 0; j < n; j++)
      a[j] = b[j];
  }
  for (int i = 0; i < n; i++) {
    cout << a[i];
    if (i != n - 1) {
      cout << ' ';
    }
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;

ll mod(ll a, ll b) {
  ll ret = a % b;
  if (ret < 0)
    ret += b;
  return ret;
}

ll modpow(ll a, ll b, ll c) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = mod(res * a, c);
    a = mod(a * a, c);
    b >>= 1;
  }
  return res;
}

int main() {
  int n, k;
  cin >> n >> k;
  ll a[n];
  bool h = true;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] < max(i, n - 1 - i))
      h = false;
  }
  if (k >= 60 or h) {
    for (int i = 0; i < n; i++) {
      cout << n;
      if (i != n - 1) {
        cout << ' ';
      }
    }
    cout << endl;
    return 0;
  }
  for (int i = 0; i < k; i++) {
    if (h) {
      for (int j = 0; j < n; j++) {
        a[j] = n;
      }
      break;
    }
    ll b[n];
    for (int j = 0; j < n; j++) {
      b[j] = 0;
    }
    for (int j = 0; j < n; j++) {
      for (int p = (j - a[j] < 0 ? 0 : j - a[j]);
           p <= (j + a[j] > n - 1 ? n - 1 : j + a[j]); p++) {
        b[p]++;
      }
    }
    h = true;
    for (int j = 0; j < n; j++) {
      a[j] = b[j];
      if (a[j] < max(j, n - 1 - j))
        h = false;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << a[i];
    if (i != n - 1) {
      cout << ' ';
    }
  }
  cout << endl;
  return 0;
}