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

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pll pair<ll, ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define lb(c, x) distance(c.begin(), lower_bound(all(c), x))
#define ub(c, x) distance(c.begin(), upper_bound(all(c), x))

using namespace std;

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 ll INF = 1e18;
const ll mod = 1e9 + 7;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> cur(n + 1), next(n + 1);
  rep(i, n) { cin >> cur[i]; }
  rep(i, k) {
    bool all = true;
    rep(j, n) {
      ll pos1 = max(j - cur[j], 0LL);
      ll pos2 = min(j + cur[j] + 1, n);
      next[pos1]++;
      next[pos2]--;
    }
    rep(j, n + 1) {
      if (j) {
        next[j] += next[j - 1];
      }
    }
    rep(j, n) {
      if (cur[j] != next[j])
        all = false;
    }
    cur = next;
    next = vector<ll>(n);
    if (all)
      break;
  }
  rep(i, n) {
    if (i)
      cout << " ";
    cout << cur[i];
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pll pair<ll, ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define lb(c, x) distance(c.begin(), lower_bound(all(c), x))
#define ub(c, x) distance(c.begin(), upper_bound(all(c), x))

using namespace std;

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 ll INF = 1e18;
const ll mod = 1e9 + 7;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> cur(n + 1), next(n + 1);
  rep(i, n) { cin >> cur[i]; }
  rep(i, k) {
    bool all = true;
    rep(j, n) {
      ll pos1 = max(j - cur[j], 0LL);
      ll pos2 = min(j + cur[j] + 1, n);
      next[pos1]++;
      next[pos2]--;
    }
    rep(j, n + 1) {
      if (j) {
        next[j] += next[j - 1];
      }
    }
    rep(j, n + 1) {
      if (cur[j] != next[j])
        all = false;
    }
    cur = next;
    next = vector<ll>(n);
    if (all)
      break;
  }
  rep(i, n) {
    if (i)
      cout << " ";
    cout << cur[i];
  }
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef pair<int, int> P;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define rrep(i, n, a) for (int i = n; i >= a; i--)
#define FOR(i, n) for (int i = 0; i < n; i++)
#define all(s) s.begin(), s.end()
#define vi vector<int>
#define vvi vector<vector<int>>

int n, k;
vi imos(200010, 0);
void display(vector<int> &a) {
  rep(i, 0, n) {
    cout << a[i];
    if (i != n - 1) {
      cout << ' ';
    }
  }
  cout << endl;
}

void query(vector<int> &a) {
  rep(i, 0, n) {
    imos[max(0, i - a[i])]++;
    imos[min(200001, i + a[i] + 1)]--;
  }
  rep(i, 1, 200010) { imos[i] += imos[i - 1]; }
  rep(i, 0, n) {
    a[i] = imos[i];
    imos[i] = 0;
  }
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  vi a(n);
  rep(i, 0, n) { cin >> a[i]; }
  if (k > 1 + (int)(-1 + sqrt(-1 + 8 * n)) / 2) {
    rep(i, 0, n) { a[i] = n; }
  } else {
    rep(i, 0, k) query(a);
  }
  rep(i, 0, n) {
    cout << a[i];
    if (i != n - 1) {
      cout << ' ';
    }
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef pair<int, int> P;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define rrep(i, n, a) for (int i = n; i >= a; i--)
#define FOR(i, n) for (int i = 0; i < n; i++)
#define all(s) s.begin(), s.end()
#define vi vector<int>
#define vvi vector<vector<int>>

int n, k;
vi imos(200010, 0);
void query(vector<int> &a) {
  rep(i, 0, n) {
    imos[max(0, i - a[i])]++;
    imos[min(200001, i + a[i] + 1)]--;
  }
  rep(i, 1, 200010) { imos[i] += imos[i - 1]; }
  rep(i, 0, n) {
    a[i] = imos[i];
    imos[i] = 0;
  }
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  vi a(n);
  rep(i, 0, n) { cin >> a[i]; }
  rep(i, 0, k) query(a);
  rep(i, 0, n) {
    cout << a[i];
    if (i != n - 1) {
      cout << ' ';
    }
  }
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template <class _T> static void getint(_T &a) { std::cin >> a; }
template <class _T> static void getint(_T &a, _T &b) { std::cin >> a >> b; }
template <class _T> static void getint(_T &a, _T &b, _T &c) {
  std::cin >> a >> b >> c;
}

static void TokioMarine2020C();

#if 1
int main() {
  TokioMarine2020C();
  fflush(stdout);
  return 0;
}
#endif

static void TokioMarine2020C() {
  int N, K;

  getint(N, K);
  std::vector<LLONG> ai(N, 0);
  for (int i = 0; i < N; i++) {
    getint(ai[i]);
  }

  for (int k = 0; k < K; k++) {
    std::vector<LLONG> bi(N, 0);
    for (int i = 0; i < N; i++) {
      LLONG left = std::max<LLONG>(0, i - ai[i]);
      LLONG right = std::min<LLONG>(N - 1, i + ai[i]);
      bi[left]++;
      if (right < N - 1) {
        bi[right + 1]--;
      }
    }

    ai[0] = bi[0];
    LLONG minRight = MOD_NUM;
    for (int i = 1; i < N; i++) {
      ai[i] = ai[i - 1] + bi[i];
      minRight = std::min(ai[i], minRight);
    }
    if (minRight >= N) {
      break;
    }
  }
  for (int i = 0; i < N; i++) {
    printf("%lld ", ai[i]);
  }
  putchar('\\n');
}


Error: TLE

Fixed submission:


#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template <class _T> static void getint(_T &a) { std::cin >> a; }
template <class _T> static void getint(_T &a, _T &b) { std::cin >> a >> b; }
template <class _T> static void getint(_T &a, _T &b, _T &c) {
  std::cin >> a >> b >> c;
}

static void TokioMarine2020C();

#if 1
int main() {
  TokioMarine2020C();
  fflush(stdout);
  return 0;
}
#endif

static void TokioMarine2020C() {
  int N, K;

  getint(N, K);
  std::vector<LLONG> ai(N, 0);
  for (int i = 0; i < N; i++) {
    getint(ai[i]);
  }

  LLONG minRight = MOD_NUM;
  for (int k = 0; k < K; k++) {
    std::vector<LLONG> bi(N, 0);
    for (int i = 0; i < N; i++) {
      LLONG left = std::max<LLONG>(0, i - ai[i]);
      LLONG right = std::min<LLONG>(N - 1, i + ai[i]);
      bi[left]++;
      if (right < N - 1) {
        bi[right + 1]--;
      }
    }

    ai[0] = bi[0];
    for (int i = 1; i < N; i++) {
      ai[i] = ai[i - 1] + bi[i];
      minRight = std::min(ai[i], minRight);
    }
    if (minRight >= N) {
      break;
    }
  }
  for (int i = 0; i < N; i++) {
    printf("%lld ", ai[i]);
  }
  putchar('\\n');
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>

using namespace std;

#define NMAX 200010

int a[NMAX];
int imos[NMAX];

void reset(int n) {
  for (int i = 0; i < n; i++)
    imos[i] = 0;
}

int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}

int min(int a, int b) {
  if (a > b)
    return b;
  else
    return a;
}

int get_int() {
  int res = 0;
  char c = getchar();
  while (c != EOF && c != ' ' && c != '\\n') {
    res *= 10;
    res += c - '0';
    c = getchar();
  }
  return res;
}

int main() {

  int n, k;
  n = get_int();
  k = get_int();
  for (int i = 0; i < n; i++)
    a[i] = get_int();

  for (int itr = 0; itr < k; itr++) {
    int f = 0;
    reset(n + 1);
    for (int i = 0; i < n; i++) {
      f = (a[i] != n);
      imos[max(0, i - a[i])]++;
      imos[min(n, i + a[i] + 1)]--;
    }
    int acc = 0;
    for (int i = 0; i < n; i++) {
      acc += imos[i];
      a[i] = acc;
    }
    if (!f)
      break;
  }

  for (int i = 0; i < n; i++)
    printf("%d\\n", a[i]);
  return 0;
}


Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

#include <cstdio>
#include <fstream>
#include <iostream>

using namespace std;

#define NMAX 200010

int a[NMAX];
int imos[NMAX];

void reset(int n) {
  for (int i = 0; i < n; i++)
    imos[i] = 0;
}

int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}

int min(int a, int b) {
  if (a > b)
    return b;
  else
    return a;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  const long long sum = n * n;
  for (int itr = 0; itr < k; itr++) {
    reset(n + 1);
    for (int i = 0; i < n; i++) {
      imos[max(0, i - a[i])]++;
      imos[min(n, i + a[i] + 1)]--;
    }
    long long acc = 0;
    for (int i = 0; i < n; i++) {
      acc += imos[i];
      a[i] = acc;
    }
    if (acc == sum)
      break;
  }

  for (int i = 0; i < n; i++)
    printf("%d\\n", a[i]);
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k, pos;
  cin >> n >> k;
  lvector A(n);
  rep(i, n) cin >> A[i];
  ll lim = min(50ll, k);
  lvector B(n, 0);
  rep(i, n) {
    pos = max(0ll, i - A[i]);
    B[pos]++;
    if (i + A[i] + 1 < n)
      B[i + A[i] + 1]--;
  }
  rep(i, n - 1) B[i + 1] += B[i];
  rep(i, lim - 1) {
    lvector tmp(n, 0);
    rep(j, n) {
      pos = max(0ll, j - B[j]);
      tmp[pos]++;
      if (j + B[j] + 1 < n)
        tmp[j + B[j] + 1]--;
    }
    rep(j, n - 1) tmp[j + 1] += tmp[j];
    rep(j, n) B[j] = tmp[j];
  }
  rep(i, n - 1) cout << B[i] << ' ';
  print(B[n - 1]);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k, pos;
  cin >> n >> k;
  lvector A(n);
  rep(i, n) cin >> A[i];
  ll lim = min(50ll, k);
  lvector B(n, 0);
  rep(i, n) {
    pos = max(0ll, i - A[i]);
    B[pos]++;
    if (i + A[i] + 1 < n)
      B[i + A[i] + 1]--;
  }
  rep(i, n - 1) B[i + 1] += B[i];
  rep(i, lim - 1) {
    lvector tmp(n, 0);
    rep(j, n) {
      pos = max(0ll, j - B[j]);
      tmp[pos]++;
      if (i + B[j] + 1 < n)
        tmp[j + B[j] + 1]--;
    }
    rep(j, n - 1) tmp[j + 1] += tmp[j];
    rep(j, n) B[j] = tmp[j];
  }
  rep(i, n - 1) cout << B[i] << ' ';
  print(B[n - 1]);
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll M = 1e9 + 7;
const ll INF = 1e9 + 7;

ll n, k, ans;
ll a[220000];
ll in[220000], out[220000];

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

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

  while (k--) {
    for (ll i = 0; i <= n; i++) {
      in[i] = out[i] = 0;
    }
    for (ll i = 0; i < n; i++) {
      in[max(0LL, i - a[i])]++;
      out[min(n, i + a[i] + 1)]++;
    }
    ll sum = 0;
    for (ll i = 0; i < n; i++) {
      sum += in[i] - out[i];
      a[i] = sum;
    }
    bool f = true;
    for (ll i = 0; i < n; i++) {
      if (a[i] != n)
        f = false;
    }
    if (f)
      break;
  }

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

Error: WA

Fixed submission:

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll M = 1e9 + 7;
const ll INF = 1e9 + 7;

ll n, k, ans;
ll a[110000];
ll in[110000], out[110000];

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

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

  while (k--) {
    for (ll i = 0; i <= n; i++) {
      in[i] = out[i] = 0;
    }
    for (ll i = 0; i < n; i++) {
      in[max(0LL, i - a[i])]++;
      out[min(n, i + a[i] + 1)]++;
    }
    ll sum = 0;
    for (ll i = 0; i < n; i++) {
      sum += in[i] - out[i];
      a[i] = sum;
    }
    bool f = true;
    for (ll i = 0; i < n - 1; i++) {
      if (a[i] != a[i + 1])
        f = false;
    }
    if (f)
      break;
  }

  for (ll i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
  return 0;
}
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++)

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> A(n);
  rep(i, n) { cin >> A[i]; }
  rep(i, k) {
    vector<int> B(n + 1);
    rep(j, n) {
      int l = max(0, (j - A[j]));
      int r = min(j + A[j] + 1, n);
      B[l]++;
      B[r]--;
    }
    rep(j, n) B[j + 1] += B[j];
    B.pop_back();
    if (A == B)
      break;
    A = B;
  }
  rep(i, n) {
    cout << A[i];
    if (i != n)
      cout << ' ';
  }
  cout << endl;
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> A(n);
  rep(i, n) { cin >> A[i]; }
  rep(i, k) {
    vector<int> B(n + 1, 0);
    rep(i, n) {
      int l = max(0, (i - A[i]));
      int r = min(i + A[i] + 1, n);
      B[l]++;
      B[r]--;
    }
    rep(j, n) B[i + 1] += B[i];
    B.pop_back();
    if (A == B)
      break;
    A = B;
  }
  rep(i, n) {
    cout << A[i];
    if (i != n)
      cout << ' ';
  }
  cout << endl;
  return 0;
}
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++)
#define repA(i, n) for (int i = n; i >= 0; i--)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a.size())
typedef long long ll;
typedef long double ld;
const ll mod = 998244353; // 1e9+7

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  while (k--) {
    vector<int> b(n + 1, 0);
    rep(i, n) {
      int from = max(0, i - a[i]);
      int to = min(n - 1, i + a[i]);
      b[from]++;
      b[to + 1]--;
    }
    bool changed = false;
    rep(i, n) {
      changed |= (a[i] != b[i]);
      a[i] = b[i];
      b[i + 1] += b[i];
    }
    if (!changed)
      break;
  }
  rep(i, n) cout << a[i] << ' ';
  cout << '\\n';
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  ll t = 1;
  //  cin>>t;
  rep(i, t) {
    solve();
    //  cout<<'\\n';
  }
  return 0;
}


Error: -6
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repA(i, n) for (int i = n; i >= 0; i--)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a.size())
typedef long long ll;
typedef long double ld;
const ll mod = 998244353; // 1e9+7

int solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  while (k--) {
    vector<int> b(n + 1, 0);
    rep(i, n) {
      int from = max(0, i - a[i]);
      int to = min(n - 1, i + a[i]);
      b[from]++;
      b[to + 1]--;
    }
    bool changed = false;
    rep(i, n) {
      changed |= (a[i] != b[i]);
      a[i] = b[i];
      b[i + 1] += b[i];
    }
    if (!changed)
      break;
  }
  rep(i, n) cout << a[i] << ' ';
  cout << '\\n';
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  ll t = 1;
  //  cin>>t;
  rep(i, t) {
    solve();
    //  cout<<'\\n';
  }
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
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];

  vector<int> b(n + 1);
  vector<int> c(n);
  int count = 0;

  for (int i = 1; i <= k; i++) {

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

    for (int i = 0; i < n; i++) {
      if (i == 0)
        c[i] = b[i];
      else
        c[i] += c[i - 1] + b[i];
    }

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

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

    if (count == n) {
      break;
    }

    count = 0;
  }

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
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];

  vector<int> b(n + 1);
  vector<int> c(n);
  int count = 0;

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

      return 0;
    }

    else {
      for (int i = 0; i < n; i++) {
        b[max(1, 1 + i - a[i]) - 1]++;
        b[min(n, 1 + i + a[i])]--;
      }

      for (int i = 0; i < n; i++) {
        if (i == 0)
          c[i] = b[i];
        else
          c[i] += c[i - 1] + b[i];
      }

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

      for (int i = 0; i < n; i++) {
        if (a[i] == n)
          count++;
        if (count == n) {
          break;
        }
        count = 0;
      }
    }
  }

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