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

#include <bits/stdc++.h>

#define lol long long
#define gcd(x, y) __gcd(x, y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed << setprecision(14)
using namespace std;
using pii = pair<int, int>;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a && (a = b, true);
}
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol inf = (1LL << 60);
const lol MOD = (1e9) + 7;
const lol mod = 998244353;
const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
lol n, m, k, r, q;
int imos[400010];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  vector<int> a(n);
  for (auto &&o : a)
    cin >> o;
  for (int r = 0; r < k; r++) {
    bool yes = true;
    for (int i = 0; i < n; i++) {
      if (i - a[i] >= 0)
        imos[i - a[i]]++;
      else
        imos[0]++;
      if (i + a[i] + 1 < n)
        imos[i + a[i] + 1]--;
    }
    int tmp = 0;
    int j = 0;
    for (auto &&o : a) {
      o = imos[j] + tmp;
      if (o != n)
        yes = false;
      tmp = o;
      imos[j] = 0;
      j++;
    }
    if (yes)
      break;
  }
  cout << a[0];
  for (int i = 1; i < n; i++)
    cout << ' ' << a[i];
  cout << '\\n';
  return (0);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define lol long long
#define gcd(x, y) __gcd(x, y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed << setprecision(14)
using namespace std;
using pii = pair<int, int>;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a && (a = b, true);
}
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol inf = (1LL << 60);
const lol MOD = (1e9) + 7;
const lol mod = 998244353;
const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
lol n, m, k, r, q;
int imos[400010];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  vector<int> a(n);
  for (auto &&o : a)
    cin >> o;
  for (int r = 0; r < k; r++) {
    for (int i = 0; i < n; i++) {
      if (i - a[i] >= 0)
        imos[i - a[i]]++;
      else
        imos[0]++;
      if (i + a[i] + 1 < n)
        imos[i + a[i] + 1]--;
    }
    int tmp = 0;
    int j = 0;
    for (auto &&o : a) {
      o = imos[j] + tmp;
      tmp = o;
      imos[j] = 0;
      j++;
    }
  }
  cout << a[0];
  for (int i = 1; i < n; i++)
    cout << ' ' << a[i];
  cout << '\\n';
  return (0);
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int a[200010], b[200001];
  int n, k, t;
  cin >> n >> k;
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  while (k--) {
    t = 0;
    for (i = 0; i < n; i++) {
      int c, d;
      c = i + a[i];
      d = max(0, i - a[i]);
      b[c + 1]--;
      b[d]++;
    }
    a[0] = b[0];
    if (a[0] == n)
      t++;
    for (i = 1; i < n; i++) {
      b[i] = b[i] + b[i - 1];
      a[i] = b[i];
      b[i - 1] = 0;
      if (a[i] == n)
        t++;
    }
    if (t == n)
      break;
    b[i - 1] = 0;
  }
  for (i = 0; i < n; i++)
    cout << a[i] << ' ';
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int a[200010], b[200001];
  int n, k, t;
  cin >> n >> k;
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  while (k--) {
    t = 0;
    for (i = 0; i < n; i++) {
      int c, d;
      c = i + a[i];
      d = max(0, i - a[i]);
      b[c + 1]--;
      b[d]++;
    }
    if (a[0] == b[0])
      t++;
    a[0] = b[0];
    for (i = 1; i < n; i++) {
      b[i] = b[i] + b[i - 1];
      if (a[i] == b[i])
        t++;
      a[i] = b[i];
      b[i - 1] = 0;
    }
    b[i - 1] = 0;
    if (t == n) {
      break;
    }
  }
  for (i = 0; i < n; i++)
    cout << a[i] << ' ';
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int, int>;
const int INF = 1e9 + 7;

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

  rep(ki, k) {
    vec b(n);
    rep(i, n) {
      int l = max(0, i - a[i]);
      int r = min(n, i + a[i] + 1);
      b[l]++;
      if (r < n)
        b[r]--;
    }
    bool f = true;
    rep(i, n - 1) { b[i + 1] += b[i]; }

    if (a == b)
      break;
    a = b;
  }

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


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int, int>;
const int INF = 1e9 + 7;

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

  rep(ki, k) {
    vec b(n);
    rep(i, n) {
      int l = max(0, i - a[i]);
      int r = min(n, i + a[i] + 1);
      b[l]++;
      if (r < n)
        b[r]--;
    }
    bool f = true;
    rep(i, n) { b[i + 1] += b[i]; }

    if (a == b)
      break;
    a = b;
  }

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

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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<int> A(N);
  rep(i, N) cin >> A[i];

  rep(k, K) {
    int n_count = 0;
    vector<int> l(N + 1, 0);
    rep(i, N) {
      if (A[i] != 0) {
        int left = std::max(i - A[i], 0);
        int right = std::min(i + A[i] + 1, N);
        l[left]++;
        l[right]--;
      } else {
        l[i]++;
        l[i + 1]--;
      }
    }
    int sum = 0;
    rep(i, N) {
      sum += l[i];
      A[i] = sum;
      if (A[i] == N)
        n_count++;
    }
    if (n_count == N) {
      break;
    }
  }

  rep(i, N - 1) { cout << A[i] << " "; }
  cout << A[N - 1] << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<int> A(N);
  rep(i, N) cin >> A[i];

  rep(k, K) {
    vector<int> l(N + 1, 0);
    rep(i, N) {
      if (A[i] != 0) {
        int left = std::max(i - A[i], 0);
        int right = std::min(i + A[i] + 1, N);
        l[left]++;
        l[right]--;
      } else {
        l[i]++;
        l[i + 1]--;
      }
    }
    int sum = 0;
    rep(i, N) {
      sum += l[i];
      A[i] = sum;
    }
  }

  rep(i, N - 1) { cout << A[i] << " "; }
  cout << A[N - 1] << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main() {
  int n, k;
  int a[220000];
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  int b[220000];
  if (k < 100) {
    while (k--) {
      rep(i, n) {
        int l = max(0, i - a[i]);
        int r = min(n - 1, i + a[i]) + 1;
        b[l]++;
        if (r < n)
          b[r]--;
      }
      rep(i, n - 1) { b[i + 1] += b[i]; }
      rep(i, n) a[i] = b[i];
      fill(b, b + 220000, 0);
    }
  } else {
    fill(a, a + 220000, n);
  }

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

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main() {
  int n, k;
  int a[200000];
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  int b[200000];
  if (k < 100) {
    while (k--) {
      rep(i, n) {
        int l = max(0, i - a[i]);
        int r = min(n - 1, i + a[i]) + 1;
        b[l]++;
        if (r < n)
          b[r]--;
      }
      rep(i, n - 1) { b[i + 1] += b[i]; }
      rep(i, n) a[i] = b[i];
      fill(b, b + 200000, 0);
    }
  } else {
    fill(a, a + 200000, n);
  }

  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++)
#define pb push_back
using namespace std;
typedef long long ll;

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

  vector<int> b(n);

  rep(i, k) {
    rep(j, n) {
      b[max(0, j - a[j])]++;
      if (j + a[j] + 1 < n)
        b[j + a[j] + 1]--;
    }
    bool flag = true;
    a[0] = b[0];
    b[0] = 0;
    if (a[0] != n)
      flag = false;
    rep(i, n - 1) {
      a[i + 1] = b[i + 1] + a[i];
      if (a[i + 1] != n)
        flag = false;
      b[i + 1] = 0;
    }
    if (flag) {
      rep(p, n) cout << n << " ";
      return 0;
    }
  }
  rep(i, n) cout << a[i] << " ";
}

Error: TLE

Fixed submission:

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

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

  vector<int> b(n);

  rep(i, k) {

    rep(j, n) {

      b[max(0, j - a[j])]++;
      if (j + a[j] + 1 < n)
        b[j + a[j] + 1]--;
    }

    a[0] = b[0];
    b[0] = 0;
    rep(i, n - 1) {
      a[i + 1] = b[i + 1] + a[i];
      b[i + 1] = 0;
    }
  }
  rep(i, n) cout << a[i] << " ";
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  k = min(k, 41);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  while (k--) {
    vector<int> b(n, 0);
    for (int i = 0; i < n; i++) {
      int l = max(i - a[i], 0), r = min(i + a[i], n - 1) + 1;
      if (r < n)
        b[r]--;
      b[l]++;
    }
    for (int i = 1; i < n; i++)
      b[i] += b[i - 1];
    for (int i = 0; i < n; i++)
      a[i] = b[i];
  }
  for (int i = 0; i < n; i++)
    cout << a[i] << " ";
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  while (k--) {
    vector<int> b(n, 1);
    bool shit = 1;
    for (int i = 0; i < n; i++)
      for (int j = 1; j <= a[i]; j++) {
        if (!i && j < n)
          b[j]++;
        else if (i == n - 1 && i >= j)
          b[i - j]++;
        else if (i && n - 1 - i) {
          if (i + j < n)
            b[i + j]++;
          if (i - j >= 0)
            b[i - j]++;
        }
      }
    for (int i = 0; i < n; i++) {
      a[i] = b[i];
      if (n - a[i])
        shit = 0;
    }
    if (shit)
      break;
  }
  for (int i = 0; i < n; i++)
    cout << a[i] << " ";
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) {
  int g = a;
  x = 1;
  y = 0;
  if (b != 0)
    g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 200005;

int N, K;
int A[2][MAX_N];

signed main() {
  cin >> N >> K;
  REP(n, N) { cin >> A[0][n]; }

  int now, next;
  REP(k, min((LL)50, K)) {
    now = k % 2;
    next = (k + 1) % 2;

    memset(A[next], 0, sizeof(A[next]));

    REP(n, N) {
      int l = max((LL)0, n - A[now][n]);
      int r = min((LL)N, n + A[now][n] + 1);
      A[next][l]++;
      A[next][r]--;
    }
    REP(n, N) { A[next][n + 1] += A[next][n]; }
  }

  REP(n, N) {
    if (0 < n) {
      cout << " ";
    }
    cout << A[next][n];
  }
  cout << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) {
  int g = a;
  x = 1;
  y = 0;
  if (b != 0)
    g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 200005;

int N, K;
int A[2][MAX_N];

signed main() {
  cin >> N >> K;
  REP(n, N) { cin >> A[0][n]; }

  int now, next;
  REP(k, min((LL)50, K)) {
    now = k % 2;
    next = (k + 1) % 2;
    REP(n, N) { memset(A[next], 0, sizeof(A[next])); }
    REP(n, N) {
      int l = max((LL)0, n - A[now][n]);
      int r = min((LL)N, n + A[now][n] + 1);
      A[next][l]++;
      A[next][r]--;
    }
    REP(n, N) { A[next][n + 1] += A[next][n]; }
  }

  REP(n, N) {
    if (0 < n) {
      cout << " ";
    }
    cout << A[next][n];
  }
  cout << endl;

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

#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>

int ans[504][200004];

int main() {
  int N, K;
  scanf("%d", &N);
  scanf("%d", &K);
  std::vector<int> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    ans[0][i] = A[i];
  }
  for (int j = 1; j < 500; j++) {
    std::vector<int> diff(N + 4, 0);
    for (int i = 0; i < N; i++) {
      if (i + ans[j - 1][i] + 1 < N)
        diff[i + ans[j - 1][i] + 1]--;
      diff[std::max(0, i - ans[j - 1][i])]++;
    }
    int counter = 0;
    for (int i = 0; i < N; i++) {
      // if (j==1) printf("diff[%d]=%d\\n", i,diff[i]);
      counter += diff[i];
      ans[j][i] = counter;
    }
  }
  if (K >= 500) {
    // for (int i=0; i<2000000000000; i++){
    for (int i = 0; i < N; i++) {
      printf("%d%c", N, (i == N - 1) ? '\\n' : ' ');
    }
  } else {
    for (int i = 0; i < N; i++) {
      printf("%d%c", ans[K][i], (i == N - 1) ? '\\n' : ' ');
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>

int ans[25][200004];

int main() {
  int N, K;
  scanf("%d", &N);
  scanf("%d", &K);
  std::vector<int> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    ans[0][i] = A[i];
  }
  for (int j = 1; j < 25; j++) {
    int left = 0;
    int right = 0;
    int target = 0;
    while (target < N) {
      while (right - target <= ans[j - 1][right] && right < N) {
        right++;
      }
      while (target - left > ans[j - 1][left] && left < right) {
        left++;
      }
      ans[j][target] = right - left;
      target++;
    }
  }
  if (K > log2(N) * 2) {
    for (int i = 0; i < N; i++) {
      printf("%d%c", N, (i == N - 1) ? '\\n' : ' ');
    }
  } else {
    for (int i = 0; i < N; i++) {
      printf("%d%c", ans[K][i], (i == N - 1) ? '\\n' : ' ');
    }
  }
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// int/long:            -2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:      -9,223,372,036,854,775,808 - 9,223,372,036,854,775,807
// (-2^63 <= long < 2^63)

#define INF (1 << 30)
// 1,073,741,824
//= 536,870,912 *2

#define MOD 1000000007

#define Rep0(i, n) for (auto i = 0; i < n; i++)
#define Rep1(i, n) for (auto i = 1; i <= n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P) reverse(P.begin(), P.end())

int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> A(N, 0);
  Rep0(i, N) cin >> A.at(i);
  Rep0(i, K) {
    vector<ll> AA(N + 1, 0);
    Rep0(j, N) {
      AA.at(max((ll)0, j - A.at(j)))++;
      AA.at(min((ll)N, j + A.at(j) + 1))--;
    }
    ll S = 0;
    int C = 0;
    Rep0(j, N) {
      S += AA.at(j);
      if (S == A.at(j))
        C++;
      else
        A.at(j) = S;
    }
    if (C == N)
      break;
  }
  Rep0(i, N) cout << A.at(i) << ' ';
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

// int/long:            -2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:      -9,223,372,036,854,775,808 - 9,223,372,036,854,775,807
// (-2^63 <= long < 2^63)

#define INF (1 << 30)
// 1,073,741,824
//= 536,870,912 *2

#define MOD 1000000007

#define Rep0(i, n) for (auto i = 0; i < n; i++)
#define Rep1(i, n) for (auto i = 1; i <= n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P) reverse(P.begin(), P.end())

int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> A(N, 0);
  Rep0(i, N) cin >> A.at(i);
  Rep0(i, K) {
    vector<ll> AA(N + 1, 0);
    Rep0(j, N) {
      AA.at(max((ll)0, j - A.at(j)))++;
      AA.at(min((ll)N, j + A.at(j) + 1))--;
    }
    ll S = 0;
    Rep0(j, N) {
      S += AA.at(j);
      A.at(j) = S;
    }
  }
  Rep0(i, N) cout << A.at(i) << ' ';
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int *a = new int[n + 1];
  int *ans = new int[n + 1];
  int i, j, ii, jj;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    ans[i] = 0;
  }
  bool allN;

  for (i = 0; i < k; i++) {
    for (j = 0; j < n; j++) {
      int limit = min(n - 1, j + a[j]);
      ii = max(0, j - a[j]);
      ans[ii]++;
      if (limit + 1 < n) {
        ans[limit + 1]--;
      }
    }

    allN = true;
    a[0] = ans[0];
    for (j = 1; j < n; j++) {
      a[j] = ans[j] = ans[j] + ans[j - 1];
      if (a[j] != n) {
        allN = false;
      }
      ans[j - 1] = 0;
    }
    ans[n - 1] = 0;
    if (allN == true)
      break;
  }

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

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int *a = new int[n + 1];
  int *ans = new int[n + 1];
  int i, j, ii, jj;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    ans[i] = 0;
  }
  bool allN;

  for (i = 0; i < k; i++) {
    allN = true;
    for (j = 0; j < n; j++) {
      int limit = min(n - 1, j + a[j]);
      for (ii = max(0, j - a[j]); ii <= limit; ii++) {
        ans[ii]++;
      }
      if (a[j] != n) {
        allN = false;
      }
    }
    if (allN == true)
      break;
    for (j = 0; j < n; j++) {
      a[j] = ans[j];
      ans[j] = 0;
    }
  }

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

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main() {
  std::size_t N, K;

  std::cin >> N >> K;
  std::vector<long int> A{}, B(N);

  A.reserve(N);

  std::size_t tmp;
  std::size_t min;
  for (auto i = 0ul; i < N; ++i) {
    std::cin >> tmp;
    A.push_back(tmp);
  }

  for (auto k = 0ul; k < K; ++k) {
    std::fill(B.begin(), B.end(), 0);
    for (auto i = 0ul; i < N; ++i) {
      auto tmp = A[i];
      if (tmp > i) {
        min = 0;
      } else {
        min = i - tmp;
      }
      B[min] += 1;
      if (auto max = tmp + i + 1; max < N) {
        B[max] -= 1;
      }
    }
    for (auto i = 1ul; i < N; ++i) {
      B[i] += B[i - 1];
    }
    if (std::equal(A.begin(), A.end(), B.begin(), B.end())) {
      break;
    }
    std::swap(A, B);
  }

  for (auto i = 0ul; i < N; ++i) {
    std::cout << A[i] << " ";
  }
  std::cout << std::endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main() {
  std::size_t N, K;

  std::cin >> N >> K;
  std::vector<std::size_t> A{}, B(N);

  A.reserve(N);

  std::size_t tmp;
  std::size_t min;
  for (auto i = 0ul; i < N; ++i) {
    std::cin >> tmp;
    A.push_back(tmp);
  }

  for (auto k = 0ul; k < K; ++k) {
    std::fill(B.begin(), B.end(), 0ul);
    for (auto i = 0ul; i < N; ++i) {
      auto tmp = A[i];
      if (tmp > i) {
        min = 0;
      } else {
        min = i - tmp;
      }
      for (auto max = std::min(i + tmp + 1, N); min < max; ++min) {
        B[min] += 1;
      }
    }
    if (std::equal(A.begin(), A.end(), B.begin(), B.end())) {
      break;
    }
    std::swap(A, B);
  }

  for (auto i = 0ul; i < N; ++i) {
    std::cout << A[i] << " ";
  }
  std::cout << std::endl;
  return 0;
}