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

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define LL long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD = 1e9 + 7;

int n, k, a[200010], b[200010];

int main() {
  cin >> n >> k;
  rep(i, n) scanf("%d", &a[i]);
  rep(i, k) {
    memset(b, 0, sizeof(b));
    rep(j, n) {
      b[max(0, j - a[j])]++;
      b[min(n, j + a[j] + 1)]--;
    }
    int cur = 0, ok = 1;
    rep(j, n) {
      cur += b[j];
      if (cur < n)
        ok = 0;
      a[j] = cur;
    }
    if (ok)
      break;
  }
  rep(i, n) printf("%d ", a[i]);
  cout << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define LL long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD = 1e9 + 7;

int n, k, a[100010], b[100010];

int main() {
  cin >> n >> k;
  rep(i, n) scanf("%d", &a[i]);
  rep(i, k) {
    memset(b, 0, sizeof(b));
    rep(j, n) {
      b[max(0, j - a[j])]++;
      b[min(n, j + a[j] + 1)]--;
    }
    int cur = 0, ok = 1;
    rep(j, n) {
      cur += b[j];
      if (cur < n)
        ok = 0;
      a[j] = cur;
    }
    if (ok)
      break;
  }
  rep(i, n) printf("%d ", a[i]);
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define rep(X, N) for (ll X = 0LL; X < (N); X++)
#define PI (acos(-1.0))
#define MODN 1000000007
#define MODN2 998244353
#define ALL(V) (V).begin(), (V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main() {

  ll n, k;
  cin >> n >> k;

  vector<int> light(n + 2);

  rep(i, n) { cin >> light[i + 1]; }

  // imos法をつかう
  vector<int> count(n + 2);

  for (int j = 0; j < k; j++) {

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

      if (i - light[i] < 1) {
        count[0]++;
      } else {
        count[i - light[i]]++;
      }

      if (i + light[i] + 1 > n) {
        count[n + 1]--;
      } else {
        count[i + light[i] + 1]--;
      }
    }

    ll sum = 0;

    for (int i = 1; i <= n + 1; i++) {
      count[i] = count[i] + count[i - 1];
      light[i] = count[i];

      if (i != n + 1)
        sum += count[i];
    }

    if (sum == n * n)
      break;

    rep(i, n + 2) { count[i] = 0; }
  }

  for (int i = 1; i <= n; i++) {
    cout << light[i] << " ";
  }

  cout << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define rep(X, N) for (ll X = 0LL; X < (N); X++)
#define PI (acos(-1.0))
#define MODN 1000000007
#define MODN2 998244353
#define ALL(V) (V).begin(), (V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main() {

  ll n, k;
  cin >> n >> k;

  vector<int> light(n + 2);

  rep(i, n) { cin >> light[i + 1]; }

  // imos法をつかう
  vector<int> count(n + 2);

  for (int j = 0; j < k; j++) {

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

      if (i - light[i] < 1) {
        count[0]++;
      } else {
        count[i - light[i]]++;
      }

      if (i + light[i] + 1 > n) {
        count[n + 1]--;
      } else {
        count[i + light[i] + 1]--;
      }
    }

    ll sum = 0;

    for (int i = 1; i <= n + 1; i++) {
      count[i] = count[i] + count[i - 1];
      light[i] = count[i];

      if (i != n)
        sum += count[i];
    }

    if (sum == n * n)
      break;

    rep(i, n + 2) { count[i] = 0; }
  }

  for (int i = 1; i <= n; i++) {
    cout << light[i] << " ";
  }

  cout << endl;

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

#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<int> a = A;
  for (int i = 0; i < K; i++) {
    vector<int> B(N + 1, 0);
    for (int j = 0; j < N; j++) {
      B[max(0, j - a[j])]++;
      B[min(N, j + a[j] + 1)]--;
    }

    for (int j = 0; j < N; j++) {
      B[j + 1] += B[j];
    }
    B.pop_back();
    if (a == B)
      break;
    a = B;
  }
  for (int i = 0; i < N; i++) {
    cout << a[i] << (i == N - 1 ? '\\n' : ' ');
  }
  return 0;
}

Error: WA

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<int> a = A;
  for (int t = 0; t < K; t++) {
    vector<int> B(N + 1, 0);
    for (int i = 0; i < N; i++) {
      int l = max(0, i - a[i]);
      int r = min(N, i + a[i] + 1);
      B[l]++;
      B[r + 1]--;
    }
    for (int i = 0; i < N; i++)
      B[i + 1] += B[i];
    B.pop_back();
    if (a == B)
      break;
    a = B;
  }
  for (int i = 0; i < N; i++) {
    cout << a[i] << (i == N - 1 ? '\\n' : ' ');
  }
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n - 1); i >= 0; --i)

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int table[MAX];

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

  vector<int> A(N);
  for (auto &i : A)
    cin >> i;

  rep(k, K) {
    bool flg = true;
    rep(i, N) flg = A[i] >= N;
    if (flg)
      break;

    rep(i, N) table[i] = 0;
    rep(i, N) {
      table[max(i - A[i], 0)]++;
      table[min(i + A[i] + 1, N)]--;
    }

    rep(i, N) {
      if (0 < i)
        table[i] += table[i - 1];
    }

    rep(i, N) {
      int res = table[i];
      A[i] = res;
    }
  }

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

Error: TLE

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n - 1); i >= 0; --i)

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int table[MAX];

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

  vector<int> A(N);
  for (auto &i : A)
    cin >> i;

  int count = 0;
  for (auto &i : A) {
    if (i != N)
      count++;
  }

  rep(k, K) {
    if (count == 0)
      break;

    memset(table, 0, sizeof(table));
    rep(i, N) {
      table[max(i - A[i], 0)]++;
      table[min(i + A[i] + 1, N)]--;
    }

    rep(i, N + 1) {
      if (0 < i)
        table[i] += table[i - 1];
    }

    rep(i, N) {
      int res = table[i];
      if (A[i] < N && res == N)
        count--;
      A[i] = res;
    }
  }

  for (auto &i : A)
    cout << i << " ";
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc {
  // 宣言
  long long a;

public:
  // 素因数分解
  void decompositPrime(long long a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long n) {
  // 割る数の初期値
  a = 2;
  // √n ≧ a ( n ≧ a * a ) の間ループ処理
  while (n >= a * a) {
    // a で割り切れたら、a は素因数
    // そして、割られる数を a で割る
    // a で割り切れなかったら、 a を 1 増加させる
    if (n % a == 0) {
      // printf("%d * ", a);
      v.push_back(a);
      n /= a;
    } else {
      a++;
    }
  }
  // 最後に残った n は素因数
  v.push_back(n);
  // printf("%d\\n", n);
}

int main() {
  // std::stack<int> stack;
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int cnt = min(k, (int)log(200000) + 1);
  for (int i = 0; i < k; i++) {
    vector<int> b(n, 0);
    for (int j = 0; j < n; j++) {
      int left = max(0, j - a[j]);
      int right = min(n - 1, j + a[j]);
      b[left]++;
      if (right < n - 1) {
        b[right + 1]--;
      }
    }
    for (int j = 1; j < n; j++) {
      b[j] += b[j - 1];
    }
    if (a == b) {
      break;
    }
    a = b;
  }
  for (int i = 0; i < n - 1; i++) {
    cout << a[i] << " ";
  }
  cout << a[n - 1] << endl;
  // cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc {
  // 宣言
  long long a;

public:
  // 素因数分解
  void decompositPrime(long long a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long n) {
  // 割る数の初期値
  a = 2;
  // √n ≧ a ( n ≧ a * a ) の間ループ処理
  while (n >= a * a) {
    // a で割り切れたら、a は素因数
    // そして、割られる数を a で割る
    // a で割り切れなかったら、 a を 1 増加させる
    if (n % a == 0) {
      // printf("%d * ", a);
      v.push_back(a);
      n /= a;
    } else {
      a++;
    }
  }
  // 最後に残った n は素因数
  v.push_back(n);
  // printf("%d\\n", n);
}

int main() {
  // std::stack<int> stack;
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int cnt = min(k, (int)log(200000) + 1);
  for (int i = 0; i < k; i++) {
    vector<int> b(n, 0);
    for (int j = 0; j < n; j++) {
      int left = max(0, j - a[j]);
      int right = min(n - 1, j + a[j]);
      b[left]++;
      if (right < n - 1) {
        b[right + 1]--;
      }
    }
    for (int j = 1; j < n; j++) {
      b[j] += b[j - 1];
    }
    a = b;
  }
  for (int i = 0; i < n - 1; i++) {
    cout << a[i] << " ";
  }
  cout << a[n - 1] << endl;
  // cout << ans << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using ll = long long;
using namespace std;
const int INFint = 1e9 + 1;
const ll INFll = (ll)1e18 + 1;
ll MOD = 1e9 + 7;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i(0); i < N; i++) {
    cin >> A[i];
  }
  vector<int> now = A;
  for (int i(0); i < K; i++) {
    vector<int> B(N);
    for (int j(0); j < N; j++) {
      B[max(0, j - A[j])]++;
      if (j + A[j] + 1 < N) {
        B[j + A[j] + 1]--;
      }
    }
    for (int j(1); j < N; j++) {
      B[j] += B[j - 1];
    }
    A = B;
    bool flag = true;
    for (int j(0); j < N; j++) {
      if (A[j] != N)
        flag = false;
    }
    if (flag)
      break;
  }
  for (int i(0); i < N; i++) {
    cout << A[i] << " ";
  }
  cout << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using ll = long long;
using namespace std;
const int INFint = 1e9 + 1;
const ll INFll = (ll)1e18 + 1;
ll MOD = 1e9 + 7;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i(0); i < N; i++) {
    cin >> A[i];
  }
  vector<int> now = A;
  for (int i(0); i < K; i++) {
    vector<int> B(N);
    for (int j(0); j < N; j++) {
      B[max(0, j - A[j])]++;
      if (j + A[j] < N) {
        B[j + A[j] + 1]--;
      }
    }
    for (int j(1); j < N; j++) {
      B[j] += B[j - 1];
    }
    A = B;
    bool flag = true;
    for (int j(0); j < N; j++) {
      if (A[j] != N)
        flag = false;
    }
    if (flag)
      break;
  }
  for (int i(0); i < N; i++) {
    cout << A[i] << " ";
  }
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

// include
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

int N, K;

void dumpVector(std::vector<int> &v) {
  int size = v.size();
  for (int i = 0; i < size; ++i) {
    std::cout << v[i] << " ";
  }
  std::cout << std::endl;
}

int main() {

  std::cin >> N >> K;
  std::vector<int> denkyu(N);

  //	電球の強さ取得
  for (int i = 0; i < N; ++i) {
    std::cin >> denkyu[i];
  }

  //	K回繰り返す
  for (int k = 0; k < K; ++k) {
    std::vector<int> ruisekiwa(N + 1);
    // 入り口出口マーキング
    for (int i = 0; i < N; ++i) {
      int left = std::max(0, i - denkyu[i]);
      int right = std::min(i + denkyu[i] + 1, N);
      //      std::cout << left << ":" << right << std::endl;
      ruisekiwa[left]++;
      ruisekiwa[right]--;
    }
    // 加算
    for (int i = 0; i < N; ++i) {
      ruisekiwa[i + 1] += ruisekiwa[i]; // 最初の要素は加算無し
    }
    ruisekiwa.pop_back();

    if (ruisekiwa == denkyu) {
      dumpVector(denkyu);
      return 0;
    }
    denkyu = ruisekiwa;
  }

  dumpVector(denkyu);
  return 0;
}


Error: TLE

Fixed submission:

// include
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

int N, K;

void makeList(int myIdx, std::list<int> &l) {
  for (int i = 0; i < N; ++i) {
    l.push_back(i);
  }
}

void dumpVector(std::vector<int> &v) {
  int size = v.size();
  for (int i = 0; i < size; ++i) {
    std::cout << v[i] << " ";
  }
  std::cout << std::endl;
}

int getLightPower(int target, std::vector<int> &dk, std::list<int> &list) {
  int result = 0;
  std::list<int>::iterator it;
  for (it = list.begin(); it != list.end();) {
    int idx = (*it);
    int len = std::abs(target - idx);
    if (dk[idx] >= len) {
      result += 1;
      it = list.erase(it);
      //      std::cout << target << " erase " << idx << std::endl;
      continue;
    }
    it++;
  }

  return result;
}

int main() {

  std::cin >> N >> K;
  std::vector<int> denkyu(N);
  std::vector<std::list<int>> rampLists(N);

  for (int i = 0; i < N; ++i) {
    std::cin >> denkyu[i];
    makeList(i, rampLists[i]);
  }

  std::vector<int> tmp(N);
  std::vector<int> tmp2(N);
  tmp = denkyu;

  for (int j = 0; j < K; ++j) {
    int skip = true;
    for (int i = 0; i < N; ++i) {
      tmp2[i] += getLightPower(i, tmp, rampLists[i]);
      if (tmp2[i] != N) {
        skip = false;
      }
    }
    if (skip) {
      dumpVector(tmp2); // ##
      return 0;
    }
    tmp = tmp2;
  }

  dumpVector(tmp2); // #
  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;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<int> b(N, N);
  vector<int> B(N);
  while (1) {
    for (int i = 0; i < N; i++) {
      int l = max(0, i - A[i]);
      int r = min(N - 1, i + A[i]);
      B[l]++;
      if (r + 1 < N)
        B[r + 1]--;
    }
    for (int i = 1; i < N; i++) {
      B[i] += B[i - 1];
    }
    K--;
    if (K <= 0 || B == b)
      break;
    A = B;
    B = vector<int>(N);
  }

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


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];
  }

  vector<int> b(N, N);
  vector<int> B(N);
  while (1) {
    for (int i = 0; i < N; i++) {
      int a = A[i];
      for (int j = max(0, i - a); j <= min(N - 1, i + a); j++) {
        B[j]++;
      }
    }
    K--;
    if (K <= 0 || B == b)
      break;
    A = B;
    B = vector<int>(N);
  }

  for (int i = 0; i < N; i++) {
    if (i)
      cout << " ";
    cout << B[i];
  }
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i <= n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(), (v).end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n, k;
  cin >> n >> k;
  vll a(n);
  REP(i, n) cin >> a[i];
  ll end = 0;
  REP(x, k) {
    vll c(n + 1), b(n);
    REP(i, n) {
      c[max(i - a[i], 0LL)]++;
      c[min(i + a[i] + 1, n)]--;
    }
    b[0] = c[0];
    REP(i, n - 1) { b[i + 1] = min(b[i] + c[i + 1], n); }
    a = b;
    end = 1;
    REP(i, n) {
      if (a[i] != n)
        end = 0;
    }
    if (end)
      break;
  }
  REP(i, n) cout << a[i] << " ";
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i <= n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(), (v).end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n, k;
  cin >> n >> k;
  vll a(n);
  REP(i, n) cin >> a[i];
  ll end = 0;
  REP(x, k) {
    vll b(n);
    REP(i, n) {
      for (ll j = i - a[i]; j <= i + a[i]; j++) {
        if (j < 0 || j >= n)
          continue;
        b[j]++;
        chmin(b[j], n);
      }
    }
    a = b;
    end = 1;
    REP(i, n) {
      if (a[i] != n)
        end = 0;
    }
    if (end)
      break;
  }
  REP(i, n) 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() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int a[200005];
  int b[200005];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = 0;
  }
  b[n] = 0;
  int d = min(50, k);

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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  int a[200005];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int b[200005];
  for (int i = 1; i <= n; i++) {
    b[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = max(i - a[i], 1); j <= min(i + a[i], n); j++) {
      b[j]++;
    }
  }
  int d = min(k, 500) - 1;
  int c[200005];
  while (d--) {
    for (int i = 1; i <= n; i++) {
      c[i] = b[i];
      b[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
      for (int j = max(i - c[i], 1); j <= min(i + c[i], n); j++) {
        b[j]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << b[i] << " ";
  }
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI 3.14159265358979
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (auto &it : A) {
    cin >> it;
  }
  vector<ll> ans = A;
  for (int k = 0; k < K; k++) {
    vector<ll> imos(N + 1, 0);
    for (int i = 0; i < N; i++) {
      ll l = max(0LL, i - ans[i]);
      ll r = min((ll)(N - 1), i + ans[i]);
      imos[l]++;
      imos[r + 1]--;
    }
    bool ok = true;
    int MAX = N;
    if (ans[0] != MAX)
      ok = false;
    ans[0] = imos[0];
    for (int i = 1; i < N; i++) {
      imos[i] += imos[i - 1];
      ans[i] = imos[i];
      if (ans[i] != MAX)
        ok = false;
    }
    if (ok) {
      for (auto it : ans)
        cout << it << " ";
      cout << endl;
      return 0;
    }
  }
  for (auto it : ans)
    cout << it << " ";
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI 3.14159265358979
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (auto &it : A) {
    cin >> it;
  }
  vector<ll> ans = A;
  for (int k = 0; k < K; k++) {
    vector<ll> imos(N + 1, 0);
    for (int i = 0; i < N; i++) {
      ll l = max(0LL, i - ans[i]);
      ll r = min((ll)(N - 1), i + ans[i]);
      imos[l]++;
      imos[r + 1]--;
    }
    bool ok = true;
    int MAX = N;
    if (ans[0] != MAX)
      ok = false;
    ans[0] = imos[0];
    for (int i = 1; i < N; i++) {
      imos[i] += imos[i - 1];
      ans[i] = imos[i];
      if (ans[i] == MAX)
        ok = false;
    }
    if (ok) {
      for (auto it : ans)
        cout << it << " ";
      cout << endl;
      return 0;
    }
  }
  for (auto it : ans)
    cout << it << " ";
  cout << endl;
  return 0;
}