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

#include <bits/stdc++.h>

#define M_PI 3.14159265358979323846 // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a, n) for (ll a = 0; a < n; a++)
#define repi(a, b, n) for (ll a = b; a < n; a++)

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

static const ll INF = 1e15;

static const ll mod = 1e9 + 7;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> prev(n);
  rep(i, n) cin >> prev[i];
  vector<ll> current(n);
  rep(_, k) {
    vector<ll> sums(n + 1, 0);
    const auto &source = prev;
    for (int i = 0; i < n; i++) {
      auto t = source[i];
      auto front = max(0LL, i - t);
      auto back = min(n, i + t + 1);
      sums[front]++;
      sums[back]--;
    }
    // cout << "back array" << endl;
    // rep(i, n + 1) {
    //     cout << sums[i] << ",";
    // }
    // cout << endl;
    ll s = 0;
    // cout << "current" << endl;
    rep(i, n) {
      s += sums[i];
      // cout << s << ",";
      current[i] = s;
    }
    bool finish = true;
    rep(i, n) {
      if (current[i] != n) {
        finish = false;
        break;
      }
    }
    swap(prev, current);
    if (finish)
      break;
  }
  rep(i, n) { cout << prev[i] << " "; }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define M_PI 3.14159265358979323846 // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a, n) for (ll a = 0; a < n; a++)
#define repi(a, b, n) for (ll a = b; a < n; a++)

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

static const ll INF = 1e15;

static const ll mod = 1e9 + 7;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> prev(n);
  rep(i, n) cin >> prev[i];
  vector<ll> current(n);
  rep(_, k) {
    vector<ll> sums(n + 1, 0);
    const auto &source = prev;
    for (int i = 0; i < n; i++) {
      auto t = source[i];
      auto front = max(0LL, i - t);
      auto back = min(n, i + t + 1);
      sums[front]++;
      sums[back]--;
    }
    // cout << "back array" << endl;
    // rep(i, n + 1) {
    //     cout << sums[i] << ",";
    // }
    // cout << endl;
    ll s = 0;
    // cout << "current" << endl;
    rep(i, n) {
      s += sums[i];
      // cout << s << ",";
      current[i] = s;
    }
    bool finish = true;
    rep(i, n) {
      if (current[i] != n) {
        finish = false;
        break;
      }
    }
    swap(prev, current);
  }
  rep(i, n) { cout << prev[i] << " "; }
  cout << endl;
  return 0;
}
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;

void solve(ll N, ll K, std::vector<ll> A) {
  vector<ll> v(N, 0);
  rep(i, K) {
    vector<ll> v(N + 1);
    rep(j, N) {
      int l = max(0, j - (int)A[j]);
      int r = min((int)N, j + (int)A[j] + 1);
      v[l]++;
      v[r]--;
    }

    rep(j, N) v[j + 1] += v[j];
    v.pop_back();
    if (A == v)
      break;
    A = v;
  }

  rep(i, N) cout << A[i] << endl;
}

int main() {
  ll N;
  scanf("%lld", &N);
  ll K;
  scanf("%lld", &K);
  std::vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, K, std::move(A));
  return 0;
}


Error: TLE

Fixed submission:

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

void solve(long long N, long long K, std::vector<long long> A) {
  vector<long long> v(N, 0);
  for (int i = 0; i < K; i++) {
    vector<long long> v(N, 0);
    for (int j = 0; j < A.size(); j++) {
      int plus_idx = max((long long)0, j - A[j]);
      v[plus_idx]++;

      if (j + A[j] < A.size() - 1) {
        int minus_idx = j + A[j] + 1;
        v[minus_idx]--;
      }
    }
    for (int j = 1; j < A.size(); j++)
      v[j] += v[j - 1];
    A = v;
  }

  for (auto a : A)
    cout << a << " ";
  cout << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, K, std::move(A));
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <assert.h>
#include <climits>
#include <cmath>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  int32_t N, K;
  cin >> N >> K;
  vector<int32_t> A(N, 0);
  for (auto &a : A) {
    cin >> a;
  }
  for (int k = 0; k < K; k++) {
    vector<int> begin(N, 0);
    vector<int> end(N, 0);
    for (int i = 0; i < N; i++) {
      int b = max(0, i - A[i]);
      int e = min(N - 1, i + A[i]);
      begin[b]++;
      end[e]++;
    }
    int cum_beg = begin[0];
    int cum_end = 0;
    A[0] = cum_beg;
    for (int i = 1; i < N; i++) {
      cum_beg += begin[i];
      cum_end += end[i - 1];
      A[i] = cum_beg - cum_end;
    }
    if (begin[0] == N && end[N - 1] == N)
      break;
  }
  for (int i = 0; i < N; i++) {
    cout << A[i] << " ";
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <climits>
#include <cmath>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  int32_t N, K;
  cin >> N >> K;
  vector<int32_t> A(N, 0);
  for (auto &a : A) {
    cin >> a;
  }
  for (int k = 0; k < K; k++) {
    vector<int> begin(N, 0);
    vector<int> end(N, 0);
    for (int i = 0; i < N; i++) {
      int b = max(0, i - A[i]);
      int e = min(N - 1, i + A[i]);
      begin[b]++;
      end[e]++;
    }
    int cum_beg = begin[0];
    int cum_end = 0;
    A[0] = cum_beg;
    for (int i = 1; i < N; i++) {
      cum_beg += begin[i];
      cum_end += end[i - 1];
      A[i] = cum_beg - cum_end;
    }
  }
  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>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  int A[N];
  for (int a = 0; a < N; a++)
    cin >> A[a];
  for (int a = 0; a < K; a++) {
    int numN = 0;
    int prefix[N + 1];
    memset(prefix, 0, sizeof(prefix));
    for (int b = 0; b < N; b++) {
      prefix[max(0, b - A[b])]++;
      prefix[min(N, b + A[b] + 1)]--;
    }
    int sum = 0;
    for (int b = 0; b < N; b++) {
      sum += prefix[b];
      A[b] = sum;
      if (A[b] == N)
        numN++;
    }
    if (numN == N)
      break;
  }
  for (int a = 0; a < N; a++)
    cout << A[a] << " ";
  cout << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, K;
  cin >> N >> K;
  int A[N];
  for (int a = 0; a < N; a++)
    cin >> A[a];
  if (N * K > 10000000) {
    for (int a = 0; a < N; a++)
      cout << N << " ";
  } else {
    for (int a = 0; a < K; a++) {
      int prefix[N + 1];
      memset(prefix, 0, sizeof(prefix));
      for (int b = 0; b < N; b++) {
        prefix[max(0, b - A[b])]++;
        prefix[min(N, b + A[b] + 1)]--;
      }
      int sum = 0;
      for (int b = 0; b < N; b++) {
        sum += prefix[b];
        A[b] = sum;
      }
    }
    for (int a = 0; a < N; a++)
      cout << A[a] << " ";
    cout << endl;
  }
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

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

template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

// container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define ALL(a) (a).begin(), (a).end()
// constant
//--------------------------------------------
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

int main() {
  LL N, K;
  cin >> N >> K;
  vector<LL> A(N);
  REP(i, N) cin >> A[i];
  REP(k, K) {
    vector<LL> nextA(N + 2, 0);
    REP(a, N) {
      nextA[max(0LL, a - A[a])]++;
      nextA[min(a + A[a], N) + 1]--;
    }
    int now = 0;
    bool flag = true;
    REP(a, N) {
      now += nextA[a];
      A[a] = now;
      if (now < N)
        flag = false;
    }
    if (flag)
      break;
  }
  REP(a, N) { cout << A[a] << " "; }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

// container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define ALL(a) (a).begin(), (a).end()
// constant
//--------------------------------------------
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

int main() {
  LL N, K;
  cin >> N >> K;
  vector<LL> A(N);
  REP(i, N) cin >> A[i];
  REP(k, K) {
    vector<LL> nextA(N + 2, 0);
    REP(a, N) {
      nextA[max(0LL, a - A[a])]++;
      nextA[min(a + A[a], N) + 1]--;
    }
    int now = 0;
    REP(a, N) {
      now += nextA[a];
      A[a] = now;
    }
  }
  REP(a, N) { cout << A[a] << " "; }
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i, a, b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

void solve() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  forn(i, 0, n) cin >> a[i];

  while (k--) {
    vi b(n + 1);
    for (int i = 0; i < n; i++) {
      int from = max(i - a[i], 0);
      int to = min(n - 1, i + a[i]);
      b[from] += 1;
      if (to < n - 1)
        b[to + 1] -= 1;
    }

    vi cpya = a;

    for (int i = 0; i < n; i++) {
      a[i] = b[i];
      b[i + 1] += b[i];
    }
    if (cpya == a)
      break;
    // for(int i =0;i<n;i+)
  }

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

int main() {
  fast;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  // int t;cin >> t;while(t--)
  solve();
}


Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i, a, b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

void solve() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  forn(i, 0, n) cin >> a[i];

  while (k--) {
    vi b(n);
    for (int i = 0; i < n; i++) {
      int from = max(i - a[i], 0);
      int to = min(n - 1, i + a[i]);
      b[from] += 1;
      if (to < n - 1)
        b[to + 1] -= 1;
    }

    vi cpya = a;

    for (int i = 0; i < n; i++) {
      a[i] = b[i];
      b[i + 1] += b[i];
    }
    if (cpya == a)
      break;
    // for(int i =0;i<n;i+)
  }

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

int main() {
  fast;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  // int t;cin >> t;while(t--)
  solve();
}
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 P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(), x.end()
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <typename T> T ceil(T a, T b) { return a / b + !!(a % b); }

int n, k;
vector<int> a;
void solve() {

  rep(p, min(k, 41)) {
    vector<int> b(n);
    rep(i, n) {
      int l = max(i - a[i], 0);
      int r = min(i + a[i], n - 1);
      b[l]++;
      if (r + 1 < n)
        b[r + 1]--;
    }
    for (int i = 1; i < n; i++)
      b[i] += b[i - 1];
    swap(a, b);
  }
  rep(s, n) {
    if (s != n - 1) {
      cout << a[s] << " ";
    } else
      cout << a[s] << endl;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n >> k;
  a.resize(n);
  rep(i, n) { cin >> a[i]; }
  solve();
  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;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(), x.end()
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <typename T> T ceil(T a, T b) { return a / b + !!(a % b); }

int n, k;
vector<int> a;
void solve() {

  rep(p, min(k, 41)) {
    vector<int> b(n);
    rep(i, n) {
      for (int j = max(i - a[i], 0); j <= min(i + a[i], n - 1); j++) {
        b[j]++;
      }
    }
    swap(a, b);
  }
  rep(s, n) {
    if (s != n - 1) {
      cout << a[s] << " ";
    } else
      cout << a[s] << endl;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n >> k;
  a.resize(n);
  rep(i, n) { cin >> a[i]; }
  solve();
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
ll N1097 = 1000000007LL;

ll N, K;
ll A[1000000];
ll d[1000000];
int main() {
  cin >> N >> K;
  for (ll i = 0; i < N; i++) {
    scanf("%ld", &A[i]);
  }
  //
  for (ll l = 0; l < K; l++) {
    for (ll i = 0; i <= N; i++) {
      d[i] = 0LL;
    }
    for (ll i = 0; i < N; i++) {
      ll a = A[i];
      d[max(0LL, i - a)] += 1;
      d[min(N, i + a + 1)] -= 1;
    }
    ll tmp = 0;
    for (ll i = 0; i < N; i++) {
      tmp += d[i];
      A[i] = tmp;
    }
    int f = 1;
    for (ll i = 0; i < N; i++) {
      if (A[i] != N) {
        f = 0;
        break;
      }
    }
    if (f) {
      break;
    }
  }
  for (ll i = 0; i < N; i++) {
    printf("%d ", A[i]);
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
ll N1097 = 1000000007LL;

ll N, K;
ll A[1000000];
ll d[1000000];
int main() {
  cin >> N >> K;
  for (ll i = 0; i < N; i++) {
    scanf("%ld", &A[i]);
  }
  //
  for (ll l = 0; l < K; l++) {
    for (ll i = 0; i <= N; i++) {
      d[i] = 0LL;
    }
    for (ll i = 0; i < N; i++) {
      ll a = A[i];
      d[max(0LL, i - a)] += 1;
      d[min(N, i + a + 1)] -= 1;
    }
    ll tmp = 0;
    for (ll i = 0; i < N; i++) {
      tmp += d[i];
      A[i] = tmp;
    }
  }
  for (ll i = 0; i < N; i++) {
    printf("%d ", A[i]);
  }
}
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> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int m = 50;
  while (m-- && k--) {
    vector<int> b(n + 1, 0);
    for (int i = 0; i < n; i++) {
      int l = i - a[i];
      int r = i + a[i];
      l = max(l, 0);
      r = min(r, n - 1);
      b[l]++;
      b[r + 1]--;
    }
    for (int i = 0; i < n; i++) {
      b[i + 1] += b[i];
      a[i] = b[i];
    }
  }
  for (int 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() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int m = n - 1;
  while (m != n && k--) {
    vector<int> b(n + 1, 0);
    for (int i = 0; i < n; i++) {
      int l = i - a[i];
      int r = i + a[i];
      l = max(l, 0);
      r = min(r, n - 1);
      b[l]++;
      b[r + 1]--;
      m = min(m, a[i]);
    }
    for (int i = 0; i < n; i++) {
      b[i + 1] += b[i];
      a[i] = b[i];
    }
  }
  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>
using namespace std;

int a[200001];
int temp[200001];

int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);

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

    int s = 0;
    bool f = true;
    for (int i = 1; i <= n; i++) {
      s += temp[i];
      a[i] = s;
      if (a[i] != n)
        f = false;
    }
    if (f)
      break;

    memset(temp, 0, sizeof(temp));
  }
  for (int i = 1; i <= n; i++)
    cout << a[i] << " ";
  return 0;
}

Error: TLE

Fixed submission:

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

struct light {
  int d;
  int st;
  int en;
} a[200001];

int temp[200001];

bool cmp(light a, light b) { return a.st < b.st; }

int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i].d);
    a[i].st = max(0, i - a[i].d);
    a[i].en = min(n, i + a[i].d);
  }

  while (k--) {
    for (int i = 1; i <= n; i++)
      for (int j = a[i].st; j <= a[i].en; j++)
        temp[j]++;

    for (int i = 1; i <= n; i++) {
      a[i].d = temp[i];
      a[i].st = max(0, i - a[i].d);
      a[i].en = min(n, i + a[i].d);
    }

    bool f = true;
    for (int i = 1; i <= n; i++)
      if (a[i].d != n)
        f = false;
    if (f)
      break;

    memset(temp, 0, sizeof(temp));
  }
  for (int i = 1; i <= n; i++)
    cout << a[i].d << " ";
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N + 2);
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  while (K--) {
    vector<ll> B(N + 2, 0);
    for (int i = 1; i <= N; i++) {
      ll a = max(1LL, i - A[i]), b = min(N, i + A[i]) + 1;
      B[a]++, B[b]--;
    }
    bool flag = 0;
    for (int i = 1; i <= N + 1; i++) {
      B[i] += B[i - 1];
      if (A[i] != B[i]) {
        flag = 1;
      }
    }
    if (!flag) {
      break;
    }
    swap(A, B);
  }
  for (int i = 1; i <= N; i++) {
    cout << A[i];
    if (i == N) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N + 1, 0);
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  vector<int> v(N + 2);
  for (int k = 0; k < K; k++) {
    for (int i = 0; i <= N + 1; i++)
      v[i] = 0;
    for (int i = 1; i <= N; i++) {
      int a = max(1, i - A[i]), b = min(N, i + A[i]) + 1;
      v[a]++, v[b]--;
    }
    long long S = 0;
    for (int i = 1; i <= N; i++) {
      A[i] = A[i - 1] + v[i];
      S += A[i];
    }
    if (S == N * N) {
      break;
    }
  }
  for (int i = 1; i <= N; i++) {
    cout << A[i];
    if (i == N) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

vector<long long> count_v(vector<long long> v) {
  long long n = v.size();

  vector<long long> ans(n, 0);
  for (long long i = 0; i < n; i++) {
    long long left = max((long long)0, i - v[i]);
    long long right = min(n - 1, i + v[i]);
    ans[left]++;
    if (right + 1 < n) {
      ans[right + 1]--;
    }
  }

  for (long long i = 1; i < n; i++) {
    ans[i] += ans[i - 1];
  }

  return ans;
}
int main() {
  long long n, k;
  cin >> n >> k;

  vector<long long> a(n);
  vector<long long> ans_n(n, n);

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

  for (long long i = 0; i < k; i++) {
    a = count_v(a);
    if (a == ans_n) {
      for (long long j = 0; j < n; j++) {
        printf("%lld ", n);
      }
      printf("\\n");
      return 0;
    }
  }

  for (long long i = 0; i < n; i++) {
    printf("%lld ", a[i]);
  }

  printf("\\n");

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

vector<long long> count_v(vector<long long> v) {
  long long n = v.size();

  vector<long long> ans(n, 0);
  for (long long i = 0; i < n; i++) {
    for (long long j = max((long long)0, i - v[i]); j <= min(n - 1, i + v[i]);
         j++) {
      ans[j]++;
    }
  }

  return ans;
}
int main() {
  long long n, k;
  cin >> n >> k;

  vector<long long> a(n);
  vector<long long> ans_n(n, n);

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

  for (long long i = 0; i < k; i++) {
    a = count_v(a);
    if (a == ans_n) {
      for (long long j = 0; j < n; j++) {
        printf("%lld ", n);
      }
      printf("\\n");
      return 0;
    }
  }

  for (long long i = 0; i < n; i++) {
    printf("%lld ", a[i]);
  }

  printf("\\n");

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

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

#define MOD 1000000007

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

  vi a(n);

  rep(i, n) { cin >> a[i]; }

  rep(_k, k) {
    vi table(n + 1, 0);
    rep(i, n) {
      table[max(i - a[i], 0)]++;
      table[min(i + a[i] + 1, n)]--;
    }
    rep(i, n) {
      if (i > 0) {
        table[i] += table[i - 1];
      }
    }

    table.pop_back();
    if (table == a) {
      break;
    }

    a = table;
  }

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


Error: TLE

Fixed submission:

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

#define MOD 1000000007

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

  vi a(n);
  vector<vector<int>> light_a(n);

  rep(i, n) {
    cin >> a[i];
    int start = i - a[i];
    if (start < 0) {
      start = 0;
    }
    for (int k = start; k <= i + a[i] && k < n; k++) {
      light_a[k].push_back(i);
    }
  }

  rep(_k, k) {
    vi table(n + 1, 0);
    rep(i, n) {
      table[max(i - a[i], 0)]++;
      table[min(i + a[i] + 1, n)]--;
    }
    rep(i, n) {
      if (i > 0) {
        table[i] += table[i - 1];
      }
    }

    table.pop_back();
    if (table == a) {
      break;
    }

    a = table;
  }

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