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

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)

#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define ALL(x) (x).begin(), (x).end()

#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000

#define PB push_back
#define MP make_pair
#define F first
#define S second

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k, i, l, r;
  cin >> n >> k;
  vector<int> a(200005);
  REP(i, n) cin >> a[i];
  vector<int> b(200005, 0);
  REP(_, min(k, 42)) {
    REP(i, n) b[i] = 0;
    REP(i, n) {
      l = max(0, (int)i - a[i]);
      r = min(n - 1, (int)i + a[i]);
      b[l] += 1;
      b[r + 1] -= 1;
    }
    REP(i, n - 1) b[i + 1] += b[i];
    REP(i, n) a[i] = b[i];
  }
  REP(i, n) cout << a[i] << " ";
}


Error: WA

Fixed submission:

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)

#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define ALL(x) (x).begin(), (x).end()

#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000

#define PB push_back
#define MP make_pair
#define F first
#define S second

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k, i, l, r;
  cin >> n >> k;
  vector<int> a(100005);
  REP(i, n) cin >> a[i];
  vector<int> b(100005, 0);
  REP(_, min(k, 42)) {
    REP(i, n) b[i] = 0;
    REP(i, n) {
      l = max(0, (int)i - a[i]);
      r = min(n - 1, (int)i + a[i]);
      b[l] += 1;
      b[r + 1] -= 1;
    }
    REP(i, n - 1) b[i + 1] += b[i];
    REP(i, n) a[i] = b[i];
  }
  REP(i, n) cout << a[i] << " ";
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
#define ordered_set                                                            \\
  tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update>

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, k;
  cin >> n >> k;
  vi arr(n);
  for (auto &it : arr) {
    cin >> it;
  }

  vi s(n, 0);
  for (int i = 0; i < k; i++) {
    ll curr = 0;
    for (int j = n - 1; j >= 0; j--) {
      s[max(0ll, j - arr[j])]++;
      if (j + arr[j] + 1 < n) {
        s[j + arr[j] + 1]--;
      }
    }

    bool fin2 = true;
    for (int j = 0; j < n; j++) {
      curr += s[j];
      s[j] = 0;
      arr[j] = curr;
      if (arr[j] != n) {
        fin2 = false;
      }
    }

    if (fin2) {
      break;
    }
  }

  for (auto it : arr) {
    cout << it << " ";
  }
  cout << "\\n";
}


Error: TLE

Fixed submission:

// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
#define ordered_set                                                            \\
  tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update>

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, k;
  cin >> n >> k;
  vi arr(n);
  for (auto &it : arr) {
    cin >> it;
  }

  for (int i = 0; i < k; i++) {
    vi b(n, -1);
    ordered_set s;
    ll curr = 0;
    for (int j = n - 1; j >= 0; j--) {
      curr++;
      s.insert({arr[j] + curr, j});
      b[j] += sz(s) - s.order_of_key({curr, LLONG_MIN});
    }

    s.clear();
    curr = 0;
    for (int j = 0; j < n; j++) {
      curr++;
      s.insert({arr[j] + curr, j});
      b[j] += sz(s) - s.order_of_key({curr, LLONG_MIN});
    }

    arr = b;
    bool fin2 = true;
    for (int j = 0; j < n; j++) {
      if (arr[j] != n) {
        fin2 = false;
        break;
      }
    }
    if (fin2) {
      break;
    }
  }
  for (auto it : arr) {
    cout << it << " ";
  }
  cout << "\\n";
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

bool done(vector<int> &A, int N) {
  for (auto x : A)
    if (x != N)
      return false;
  return true;
}

vector<int> eval(vector<int> &A, int N) {
  vector<int> cumul(2 * N, 0);
  for (int i = 0; i < N; i++)
    cumul[max(0, i - A[i])]++, cumul[i + A[i] + 1]--;
  vector<int> ret(N, 0);
  ret[0] = cumul[0];
  for (int i = 1; i < N; i++)
    ret[i] = ret[i - 1] + cumul[i];
  return ret;
}

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < K; i++) {
    if (done(A, N))
      break;
    A = eval(A, N);
  }
  for (int i = 0; i < N; i++)
    cout << A[i] << " ";
  cout << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

bool done(vector<int> &A, int N) {
  for (auto x : A)
    if (x != N)
      return false;
  return true;
}

vector<int> eval(vector<int> &A, int N) {
  map<int, int> cumul;
  for (int i = 0; i < N; i++)
    cumul[max(0, i - A[i])]++, cumul[i + A[i] + 1]--;
  vector<int> ret(N, 0);
  ret[0] = cumul[0];
  for (int i = 1; i < N; i++)
    ret[i] = ret[i - 1] + cumul[i];
  return ret;
}

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < K; i++) {
    if (done(A, N))
      break;
    A = eval(A, N);
  }
  for (int i = 0; i < N; i++)
    cout << A[i] << " ";
  cout << "\\n";
  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> inp(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> inp.at(i);
    // inp.at(i) = 0;
  }

  vector<int> data(n + 2, 0);

  if (k >= 2000) {
    k = 2000;
  }

  for (int j = 0; j < k; j++) {
    for (int i = 1; i <= n; i++) {
      int left = max(i - inp.at(i), 1);
      int right = min(i + inp.at(i) + 1, n + 1);
      data.at(left)++;
      data.at(right)--;
    }
    int temp = 0;
    for (int i = 1; i <= n; i++) {
      temp += data.at(i);
      data.at(i) = 0;
      inp.at(i) = temp;
    }
  }

  // 確認用
  for (int i = 1; i <= n; i++) {
    cout << inp.at(i);
    if (i != n) {
      cout << " ";
    }
  }
  // cout << " " << j+1 << endl;
  cout << endl;
}

Error: TLE

Fixed submission:

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

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

  vector<int> inp(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> inp.at(i);
    // inp.at(i) = 0;
  }

  vector<int> data(n + 2, 0);

  if (k >= 3000) {
    k = 3000;
  }

  for (int j = 0; j < k; j++) {
    for (int i = 1; i <= n; i++) {
      int left = max(i - inp.at(i), 1);
      int right = min(i + inp.at(i) + 1, n + 1);
      data.at(left)++;
      data.at(right)--;
    }
    int temp = 0;
    for (int i = 1; i <= n; i++) {
      temp += data.at(i);
      data.at(i) = 0;
      inp.at(i) = temp;
    }
  }

  // 確認用
  for (int i = 1; i <= n; i++) {
    cout << inp.at(i);
    if (i != n) {
      cout << " ";
    }
  }
  // cout << " " << j+1 << endl;
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

/**
 *    created: 13.06.2020 21:08:42
 **/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  rep(ki, k) {
    vector<int> b(n + 1);
    rep(i, n) {
      int l = max(0, i - a[i]);
      int r = min(i + a[i] + 1, n);
      b[l]++;
      b[r]--;
    }
    rep(i, n) b[i + 1] += b[i];
    b.pop_back();
    if (a == b)
      break;
    a = b;
  }
  rep(i, n) cout << a[i] << endl;
  return 0;
}

Error: WA

Fixed submission:

/**
 *    created: 13.06.2020 21:08:42
 **/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[k];
  rep(ki, k) {
    vector<int> b(n + 1);
    rep(i, n) {
      int l = max(0, i - a[i]);
      int r = min(i + a[i] + 1, n);
      b[l]++;
      b[r]--;
    }
    rep(i, n) b[i + 1] += b[i];
    b.pop_back();
    if (a == b)
      break;
    a = b;
  }
  rep(i, n) cout << a[i] << 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;

int main() {
  cin.tie(0)->sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<int> a(n, 0);
  REP(i, n) cin >> a[i];

  REP(o, k) {
    vector<int> b(n + 1, 0);
    REP(i, n) {
      int l = max(0, i - a[i]);
      int r = min(n, i + a[i] + 1);
      b[l]++;
      b[r]--;
    }
    REP(i, n) b[i + 1] += b[i];
    b.pop_back();
    if (a == b)
      break;
    a = b;
  }

  REP(i, n) {
    cout << a[i];
    if (i != n - 1)
      cout << ' ';
  }
  cout << '\\n';
  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;

int main() {
  cin.tie(0)->sync_with_stdio(false);

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];

  vector<ll> tmp(n);
  tmp = a;

  REP(x, k) {
    vector<ll> cnt(n, 0);
    REP(i, n) {
      ll mini = i - a[i];
      ll maxi = i + a[i];
      for (ll j = mini; j <= maxi; j++)
        if (j >= 0 && j <= n - 1)
          cnt[j]++;
    }
    a = cnt;
    ll cntMax = 0;
    REP(i, n) if (a[i] == n) cntMax++;
    if (cntMax == n)
      break;
  }
  REP(i, n) cout << a[i] << ' ';
  cout << '\\n';
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long double ld;

const int inf = 1e9;
const ll inf64 = 1e18;

void show(vector<int> a) {
  for (int x : a)
    cout << x << " ";
  cout << "\\n";
}

vector<int> read(int n) {
  vector<int> a(n);
  for (int &x : a)
    cin >> x;
  return a;
}

vector<int> slow(vector<int> a, int k) {
  int n = (int)a.size();
  vector<int> b(n);
  for (int iter = 0; iter < k; iter++) {

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

    if (a != b)
      a = b;
    else
      break;

    //        cout << iter << " : ";
    //        cout << endl;
    //        show(a);
  }

  return a;
}

int main() {

#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, k;
  cin >> n >> k;

  vector<int> a = read(n);
  //    vector<int> a(n);

  a = slow(a, k);

  show(a);

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long double ld;

const int inf = 1e9;
const ll inf64 = 1e18;

void show(vector<int> a) {
  for (int x : a)
    cout << x << " ";
  cout << "\\n";
}

vector<int> read(int n) {
  vector<int> a(n);
  for (int &x : a)
    cin >> x;
  return a;
}

vector<int> slow(vector<int> a, int k) {
  for (int iter = 0; iter < k; iter++) {
    vector<int> b(a.size());

    multiset<int> q;

    for (int i = 0; i < (int)a.size(); i++) {
      q.insert(i + a[i]);
      while (!q.empty() && *q.begin() < i)
        q.erase(q.begin());
      b[i] += (int)q.size();
    }

    q.clear();

    for (int i = (int)a.size() - 1; i >= 0; i--) {
      q.insert(i - a[i]);
      while (!q.empty() && *(--q.end()) > i)
        q.erase(--q.end());
      b[i] += (int)q.size() - 1;
    }

    if (a != b)
      a = b;
    else
      break;

    //        cout << iter << " : ";
    //        cout << endl;
    //        show(a);
  }

  return a;
}

int main() {

#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, k;
  cin >> n >> k;

  vector<int> a = read(n);
  //    vector<int> a(n);

  a = slow(a, k);

  show(a);

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

#include <bits/stdc++.h>

using i64 = int64_t;
template <class T> using Vec = std::vector<T>;
template <class K, class V> using UM = std::unordered_map<K, V>;

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n, k;
  cin >> n >> k;

  Vec<int> as(n);
  for (auto &a : as)
    cin >> a;

  for (int ik = 0; ik < k; ++ik) {
    Vec<int> bs(n + 1);

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

    for (int i = 0; i < n; ++i)
      bs[i + 1] += bs[i];
    bs.pop_back();

    swap(as, bs);
    if (bs == as)
      break;
  }

  for (auto a : as)
    cout << a << " ";

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using i64 = int64_t;
template <class T> using Vec = std::vector<T>;
template <class K, class V> using UM = std::unordered_map<K, V>;

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n, k;
  cin >> n >> k;

  Vec<int> as(n);
  for (auto &a : as)
    cin >> a;

  for (int i = 0; i < k; ++i) {
    Vec<int> bs(n);

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

    swap(as, bs);
    if (bs == as)
      break;
  }

  for (auto a : as)
    cout << a << " ";

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

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, k;
  cin >> n >> k;
  int i, a[n], b[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = 0;
  }
  while (k--) {
    int count = 0;
    for (i = 0; i < n; i++) {
      if (1) {
        if (i - a[i] < 0)
          b[0]++;
        else
          b[i - a[i]]++;
        if (i + a[i] + 1 < n)
          b[i + a[i] + 1]--;
      }
    }
    for (i = 1; i < n; i++)
      b[i] += b[i - 1];
    for (i = 0; i < n; i++) {
      a[i] = b[i];
      b[i] = 0;
      if (a[i] == n)
        count++;
    }
    if (count == n)
      break;
  }
  for (i = 0; i < n; i++)
    cout << a[i] << " ";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int t;
  t = 1;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int org[n], ne[n], i, j;
    for (i = 0; i < n; i++) {
      cin >> org[i];
      ne[i] = 0;
    }
    while (k--) {
      for (i = 0; i < n; i++) {
        ne[i]++;
        for (j = 1; j <= org[i]; j++) {
          if (i - j >= 0)
            ne[i - j]++;
          if (i + j < n)
            ne[i + j]++;
        }
      }
      for (i = 0; i < n; i++) {
        org[i] = ne[i];
        ne[i] = 0;
      }
    }
    for (i = 0; i < n; i++)
      cout << org[i] << " ";
  }
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

// int32_t A[2][200000];

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

  int32_t N, K;
  cin >> N >> K;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int32_t> A(N + 2);
  for (int32_t i = 1; i <= N; ++i) {
    cin >> A[i];
  }
  for (int32_t k = 0; k < min(K, 1000); ++k) {
    vector<int32_t> S(N + 2, 0);
    for (int32_t i = 1; i <= N; ++i) {
      ++S[max(i - A[i], 0)];
      --S[min(i + A[i] + 1, N + 1)];
    }
    int32_t sum_value = 0;
    for (int32_t i = 0; i <= N + 1; ++i) {
      sum_value += S[i];
      A[i] = sum_value;
    }
  }
  for (int32_t i = 1; i <= N; ++i) {
    if (i != 1) {
      cout << " ";
    }
    cout << A[i];
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

// int32_t A[2][200000];

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

  int32_t N, K;
  cin >> N >> K;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int32_t> A(N + 2);
  for (int32_t i = 1; i <= N; ++i) {
    cin >> A[i];
  }
  for (int32_t k = 0; k < K; ++k) {
    vector<int32_t> S(N + 2, 0);
    for (int32_t i = 1; i <= N; ++i) {
      ++S[max(i - A[i], 0)];
      --S[min(i + A[i] + 1, N + 1)];
    }
    int32_t sum_value = 0;
    bool finished = true;
    for (int32_t i = 0; i <= N + 1; ++i) {
      sum_value += S[i];
      A[i] = sum_value;
      if (A[i] != N) {
        finished = false;
      }
    }
    if (finished) {
      break;
    }
  }
  for (int32_t i = 1; i <= N; ++i) {
    if (i != 1) {
      cout << " ";
    }
    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;
  vector<int> A(N), B(N), C(N);
  vector<int> D(N, N);

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int a = 0; a < K; a++) {
    if (A == D)
      break;
    for (int i = 0; i < N; i++) {
      int j = max(0, i - A.at(i));
      B.at(j)++;
      int l = min(N - 1, i + A.at(i));
      if (l < N - 1)
        B.at(l + 1)--;
    }
    for (int i = 1; i < N; i++)
      B.at(i) += B.at(i - 1);
    A = B;
    B = C;
  }
  C = A;

  for (int i = 0; i < N; i++) {
    cout << C.at(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), B(N), C(N);
  vector<int> D(N, N);

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int a = 0; a < K; a++) {
    if (A == D)
      break;
    for (int i = 0; i < N; i++) {
      for (int j = max(0, i - A.at(i)); j < min(N, i + A.at(i) + 1); j++) {
        B.at(j) += 1;
      }
    }
    A = B;
    B = C;
  }
  C = A;

  for (int i = 0; i < N; i++) {
    cout << C.at(i) << " ";
  }
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
const int inf = 1e+9;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> cur_v(n, 0);

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

  rep(i, k) {
    vector<int> next_v(n, 0);
    vector<int> imos(n, 0);
    rep(j, n) {
      int l = j - cur_v[j];
      int r = j + cur_v[j] + 1;
      if (l < 0) {
        l = 0;
      }
      imos[l]++;
      if (r < n) {
        imos[r]--;
      }
    }

    int cur = 0;
    rep(j, n) {
      cur += imos[j];
      next_v[j] = cur;
    }

    if (cur_v == next_v) {
      break;
    }
    cur_v = next_v;
  }

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

  return 0;
}


Error: WA

Fixed submission:

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
const int inf = 1e+9;

int main() {
  int n, k;
  cin >> n >> k;
  int a[20000][n];
  rep(i, 20000) {
    rep(j, n) { a[i][j] = 0; }
  }

  rep(i, n) { cin >> a[0][i]; }
  int last = k;
  rep(i, k) {
    vector<int> imos(n, 0);
    rep(j, n) {
      int l = j - a[i][j];
      int r = j + a[i][j] + 1;
      if (l < 0) {
        l = 0;
      }
      imos[l]++;
      if (r < n) {
        imos[r]--;
      }
    }

    int cur = 0;
    rep(j, n) {
      cur += imos[j];
      a[i + 1][j] = cur;
    }
    bool is_same = true;
    rep(j, n) {
      if (a[i][j] != a[i + 1][j]) {
        is_same = false;
        break;
      }
    }
    if (is_same) {
      last = i;
      break;
    }
  }

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

  return 0;
}