alexjercan/bugnet huggingface dataset:
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 + 1, 0);
  int MAXL = (N + 1) * 2 + 10;

  for (int i = 0; i < N; i++)
    cin >> A[i + 1];

  vector<int> temp(N + 1, 0);
  while (K) {
    vector<int> B(MAXL + 10, 0);

    for (int i = 1; i <= N; i++) {
      int sub1 = (i - A[i]) * 2 - 1;
      if (sub1 < 0)
        sub1 = 0;
      int sub2 = (i + A[i]) * 2 + 1;
      if (sub2 > MAXL - 2)
        sub2 = MAXL - 2;
      B.at(sub1)++;
      B.at(sub2 + 1)--;
    }

    for (int i = 1; i < MAXL; i++) {
      B.at(i) += B.at(i - 1);
    }

    for (int i = 0; i < N; i++)
      A.at(i + 1) = B.at((i + 1) * 2);

    if (temp == A)
      break;
    temp = A;
    K--;
    /*
    cout << "-----------" << endl;
    for(int i=0;i<N;i++)cout << A[i+1] << " ";
    cout << endl;*/
  }

  for (int i = 0; i < N; i++)
    cout << A[i + 1] << " ";
  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 + 1, 0);
  int MAXL = (N + 1) * 2 + 10;

  for (int i = 0; i < N; i++)
    cin >> A[i + 1];

  while (K) {
    vector<int> B(MAXL + 10, 0);

    for (int i = 1; i <= N; i++) {
      int sub1 = (i - A[i]) * 2 - 1;
      if (sub1 < 0)
        sub1 = 0;
      int sub2 = (i + A[i]) * 2 + 1;
      if (sub2 > MAXL - 2)
        sub2 = MAXL - 2;
      B.at(sub1)++;
      B.at(sub2 + 1)--;
    }
    for (int i = 1; i < MAXL; i++) {
      B.at(i) += B.at(i - 1);
    }

    for (int i = 0; i < N; i++)
      A.at(i + 1) = B.at((i + 1) * 2);
    K--;
  }
  for (int i = 0; i < N; i++)
    cout << A[i + 1] << " ";
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define PI 3.14159265358979323846264338327950L

int main(void) {
  long long N, K, A, tmp;

  cin >> N >> K;

  vector<long long> light(N), light_tmp(N + 1, 0), reset(N, 0);

  for (long long i = 0; i < N; i++) {
    cin >> A;
    light[i] = A;
  }

  for (long long i = 0; i < min(K, (long long)41); i++) {
    light_tmp = reset;
    for (long long j = 0; j < N; j++) {

      // for (long long s = j - light[j]; s <= j + light[j] + 0.5; s++) {
      // 	if (s < 0) { continue; }
      // 	if (s >= N ) { continue; }

      // 	light_tmp[s]++;
      // }
      tmp = max((long long)0, j - light[j]);
      light_tmp[tmp]++;

      tmp = min(j + light[j] + 1, N + 1);
      light_tmp[tmp]--;
    }

    light[0] = light_tmp[0];
    for (long long j = 1; j < N; j++) {
      light[j] = light[j - 1] + light_tmp[j];
    }
  }

  for (long long i = 0; i < N - 1; i++) {
    cout << light[i] << " ";
  }
  cout << light[light.size() - 1] << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define PI 3.14159265358979323846264338327950L

int main(void) {
  long long N, K, A;

  cin >> N >> K;

  vector<long long> light(N), light_tmp(N, 0), reset(N, 0);

  for (long long i = 0; i < N; i++) {
    cin >> A;
    light[i] = A;
  }

  for (long long i = 0; i < min(K, (long long)41); i++) {
    light_tmp = reset;
    for (long long j = 0; j < N; j++) {

      for (long long s = j - light[j]; s <= j + light[j] + 0.5; s++) {
        if (s < 0) {
          continue;
        }
        if (s >= N) {
          continue;
        }

        light_tmp[s]++;
      }
    }
    light = light_tmp;
  }

  for (long long i = 0; i < N - 1; i++) {
    cout << light[i] << " ";
  }
  cout << light[light.size() - 1] << endl;

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

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

#define SEG_LEN (1 << 18)

int seg[SEG_LEN * 2];

// one point
long long int get(int ind) {
  ind += SEG_LEN;
  long long int sum = 0;
  sum += seg[ind];
  while (true) {
    ind /= 2;
    if (ind == 0)
      break;
    sum += seg[ind];
  }
  return sum;
}

// range
void add(int l, int r, int x) {
  l += SEG_LEN;
  r += SEG_LEN;
  while (l < r) {
    if (l % 2 == 1) {
      seg[l] += x;
      l++;
    }
    l /= 2;
    if (r % 2 == 1) {
      seg[r - 1] += x;
      r--;
    }
    r /= 2;
  }
}

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

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

  rep(i, n) { add(i, i + 1, a[i]); }

  rep(c, 200) {
    if (c == k)
      break;
    vector<pair<ll, ll>> addd(n);
    rep(i, n) {
      int l = max(i - get(i), 0ll);
      int r = min(i + get(i), n - 1);

      addd[i] = make_pair(l, r);
    }

    vector<int> tmp(n);
    rep(i, n) tmp[i] = get(i);

    rep(i, n) {
      int l = addd[i].first;
      int r = addd[i].second;
      add(l, r + 1, 1);
    }

    rep(i, n) { add(i, i + 1, -tmp[i]); }
    bool flg = true;
    rep(i, n) {
      if (get(i) != n) {
        flg = false;
        break;
      }
    }

    if (flg)
      break;
  }

  rep(j, n - 1) { cout << get(j) << " "; }
  cout << get(n - 1) << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

#define SEG_LEN (1 << 18)

int seg[SEG_LEN * 2];

// one point
long long int get(int ind) {
  ind += SEG_LEN;
  long long int sum = 0;
  sum += seg[ind];
  while (true) {
    ind /= 2;
    if (ind == 0)
      break;
    sum += seg[ind];
  }
  return sum;
}

// range
void add(int l, int r, int x) {
  l += SEG_LEN;
  r += SEG_LEN;
  while (l < r) {
    if (l % 2 == 1) {
      seg[l] += x;
      l++;
    }
    l /= 2;
    if (r % 2 == 1) {
      seg[r - 1] += x;
      r--;
    }
    r /= 2;
  }
}

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

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

  rep(i, n) { add(i, i + 1, a[i]); }

  rep(c, 200) {
    if (c == k)
      break;
    vector<pair<ll, ll>> addd(n);
    rep(i, n) {
      int l = max(i - get(i), 0ll);
      int r = min(i + get(i), n - 1);

      addd[i] = make_pair(l, r);
    }

    vector<int> tmp(n);
    rep(i, n) tmp[i] = get(i);

    rep(i, n) {
      int l = addd[i].first;
      int r = addd[i].second;
      add(l, r + 1, 1);
    }

    rep(i, n) { add(i, i + 1, -tmp[i]); }
  }

  rep(j, n - 1) { cout << get(j) << " "; }
  cout << get(n - 1) << endl;

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a) { return is >> a.first >> a.second; }
ostream &operator<<(ostream &os, const P &a) {
  return os << "(" << a.first << "," << a.second << ")";
}

template <typename T> void view(const std::vector<T> &v) {
  for (const auto &e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T> void view(const std::vector<std::vector<T>> &vv) {
  for (const auto &v : vv) {
    view(v);
  }
}
#pragma endregion

int main() {
  int n, k;
  cin >> n >> k;
  vint a(n + 1);
  rep(i, n) cin >> a[i];

  vint b(n);
  rep(i, k) {
    bool maxed = true;
    b = vint(n);
    rep(j, n) {
      int l = a[j];
      int low = max(0, j - l);
      int hig = min(n - 1, j + l);

      b[low]++;
      if (hig < n - 1)
        b[hig + 1]--;
    }

    a = vint(n + 1);
    rep(j, n) {
      if (j > 0)
        a[j] += a[j - 1];
      a[j] += b[j];
      maxed = maxed && a[j] >= n;
    }

    if (maxed) {
      break;
    }
  }

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

  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a) { return is >> a.first >> a.second; }
ostream &operator<<(ostream &os, const P &a) {
  return os << "(" << a.first << "," << a.second << ")";
}

template <typename T> void view(const std::vector<T> &v) {
  for (const auto &e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T> void view(const std::vector<std::vector<T>> &vv) {
  for (const auto &v : vv) {
    view(v);
  }
}
#pragma endregion

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

  vint b(n);
  rep(i, k) {
    bool maxed = true;
    b = vint(n, 1);
    rep(j, n) {
      maxed = a[j] == n && maxed;
      rep(l, a[j]) {
        if (j - l - 1 >= 0) {
          b[j - l - 1] += 1;
        }
        if (j + l + 1 < n) {
          b[j + l + 1] += 1;
        }
      }
    }
    swap(a, b);
    if (maxed) {
      break;
    }
  }

  view(a);

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

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const int MAX = 510000;
const double pi = acos(-1);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  while (k--) {
    vector<ll> b(n + 1, 0);
    rep(i, n) {
      ll left = max(0ll, i - a[i]);
      ll right = min(n, i + a[i] + 1);
      b[left]++;
      b[right]--;
    }
    rep(i, n) {
      a[i] = b[i];
      b[i + 1] += b[i];
    }
    bool ok = true;
    rep(i, n) if (a[i] != n) ok = false;
    if (ok)
      break;
  }
  rep(i, n) cout << a[i] << " ";
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const int MAX = 510000;
const double pi = acos(-1);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  vector<vector<ll>> vec(k + 1, vector<ll>(n + 1, 0));
  rep(i, n) { cin >> vec[0][i]; }
  bool ok = true;
  ll res = 0;
  rep(i, k) {
    rep(j, n) {
      ll num = vec[i][j];
      ll left = max(0ll, j - num);
      ll right = min(n, j + num + 1ll);
      vec[i + 1][left]++;
      vec[i + 1][right]--;
    }
    vec[i + 1][n] = 1e9;
    ll m = 1e9;
    rep(j, n) { vec[i + 1][j + 1] += vec[i + 1][j]; }
    rep(j, n) m = min(vec[i + 1][j], m);
    if (m == n) {
      res = i + 1;
      ok = false;
      break;
    }
  }
  if (ok) {
    rep(i, n) {
      if (i != 0)
        cout << " ";
      cout << vec[k][i];
    }
  } else {
    rep(i, n) {
      if (i != 0)
        cout << " ";
      cout << vec[res][i];
    }
  }
  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 FOR(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e12)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T> using arr = vector<vector<T>>;
template <class T> void pr(T x) { cout << x << endl; }
template <class T> void prvec(vector<T> &a) {
  rep(i, a.size() - 1) { cout << a[i] << " "; }
  cout << a[a.size() - 1] << endl;
}
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;
}

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

  rep(ki, k) {
    vector<int> b(n + 1, 0);
    rep(i, n) {
      int l = max(i - a[i], 0);
      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;
  }
  prvec(a);

  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 FOR(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e12)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T> using arr = vector<vector<T>>;
template <class T> void pr(T x) { cout << x << endl; }
template <class T> void prvec(vector<T> &a) {
  rep(i, a.size() - 1) { cout << a[i] << " "; }
  cout << a[a.size() - 1] << endl;
}
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;
}

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

  bool is_all = false;
  int cnt = 0;
  // prvec(a);
  while (cnt < k) {
    vector<ll> b(n, 0);
    rep(i, n) {
      for (ll j = i - a[i]; j <= i + a[i]; j++) {
        if (j < 0)
          continue;
        if (j >= n)
          break;
        b[j]++;
      }
    }
    is_all = true;
    rep(i, n) {
      if (b[i] >= (ll)i && b[i] >= n - 1 - i)
        continue;
      else {
        is_all = false;
        break;
      }
    }
    a = b;
    // prvec(a);
    cnt++;
    if (is_all)
      break;
  }

  if (cnt == k) {
    prvec(a);
    return 0;
  }

  k -= cnt;

  rep(i, n) { a[i] += k * n; }
  prvec(a);
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

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

void Main() {
  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++) {
    vector<int> p1(n), p2(n + 1);
    for (int j = 0; j < n; j++) {
      p1[max(0, j - a[j])] += 1;
      p2[min(j + a[j] + 1, n)] += 1;
    }
    for (int j = 1; j < n; j++) {
      p1[j] = p1[j - 1] + p1[j];
      p2[j] = p2[j - 1] + p2[j];
    }
    for (int j = 0; j < n; j++) {
      a[j] = p1[j] - p2[j];
    }

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

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

int main(int argc, char **argv) {
  Main();
  return 0;
}


Error: WA

Fixed submission:

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

void Main() {
  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++) {
    vector<int> p1(n), p2(n);
    for (int j = 0; j < n; j++) {
      p1[max(0, j - a[j])] += 1;
      p2[j + a[j] + 1] += 1;
    }
    for (int j = 1; j < n; j++) {
      p1[j] = p1[j - 1] + p1[j];
      p2[j] = p2[j - 1] + p2[j];
    }
    for (int j = 0; j < n; j++) {
      a[j] = p1[j] - p2[j];
    }

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

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

int main(int argc, char **argv) {
  Main();
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long num, k;
  long long tmp1, tmp2;
  long long Min = 0;

  cin >> num >> k;
  // vector<long long> vec(num,0);
  vector<long long> d(num, 0);

  for (int i = 0; i < num; i++)
    cin >> d.at(i);

  for (int i = 0; i < k; i++) {
    vector<long long> vec(num + 1, 0);
    for (int j = 0; j < num; j++) {
      tmp1 = max(Min, (j + 1) - d.at(j) - 1);
      tmp2 = min(num, (j + 1) + d.at(j));

      vec.at(tmp1)++;
      vec.at(tmp2)--;
    }

    for (int j = 0; j < num; j++) {
      vec.at(j + 1) += vec.at(j);
    }
    vec.pop_back();

    if (d == vec)
      break;

    d = vec;
  }

  for (int i = 0; i < num; i++) {
    cout << d.at(i) << " ";
  }
}

Error: TLE

Fixed submission:

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

int main() {
  long long num, k;
  long long tmp1, tmp2;
  long long Min = 0;

  cin >> num >> k;
  // vector<long long> vec(num,0);
  vector<long long> d(num, 0);

  for (int i = 0; i < num; i++)
    cin >> d.at(i);

  for (int i = 0; i < k; i++) {
    vector<long long> vec(num + 1, 0);
    for (int j = 0; j < num; j++) {
      tmp1 = max(Min, (j + 1) - d.at(j) - 1);
      tmp2 = min(num, (j + 1) + d.at(j));

      vec.at(tmp1)++;
      vec.at(tmp2)--;
    }

    for (int j = 0; j < num; j++) {
      vec.at(j + 1) += vec.at(j);
    }

    d = vec;
  }

  for (int i = 0; i < num; i++) {
    cout << d.at(i) << " ";
  }
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, k, a[maxn], d[maxn];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  while (k--) {
    bool f = true;
    for (int i = 1; i <= n; i++)
      if (a[i] != n)
        f = false;
    if (f)
      break;
    for (int i = 0; i <= n + 1; i++)
      d[i] = 0;
    for (int i = 1; i <= n; i++) {
      int l = max(i - a[i], 1), r = min(i + a[i], n);
      d[l]++, d[r + 1]--;
    }
    for (int i = 1; i <= n; i++)
      d[i] += d[i - 1];
    for (int i = 1; i <= n; i++)
      a[i] = d[i];
  }
  for (int i = 1; i <= n; i++)
    printf("%d%s", a[i], i == n ? "\\n" : " ");
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, k, a[maxn], d[maxn];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  while (k--) {
    for (int i = 0; i <= n + 1; i++)
      d[i] = 0;
    for (int i = 1; i <= n; i++) {
      int l = max(i - a[i], 1), r = min(i + a[i], n);
      d[l]++, d[r + 1]--;
    }
    for (int i = 1; i <= n; i++)
      d[i] += d[i - 1];
    for (int i = 1; i <= n; i++)
      a[i] = d[i];
  }
  for (int i = 1; i <= n; i++)
    printf("%d%s", a[i], i == n ? "\\n" : " ");
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep_ll(i, x, n) for (ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];

  rep(i, 0, k) {
    vector<int> d(n + 1, 0); // nが境界にはならないから
    rep(j, 0, n) {
      ll l = max(0, j - a[j]);
      ll r = min(n, j + a[j] + 1);
      d[l]++;
      d[r]--;
    }
    rep(j, 1, n) d[j] += d[j - 1];
    d.pop_back();
    swap(a, d);
    if (a == d)
      break;
  }
  rep(i, 0, n) cout << a[i] << " ";

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep_ll(i, x, n) for (ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];

  rep(i, 0, k) {
    vector<int> d(n, 0);
    rep(j, 0, n) {
      ll l = max(0, j - a[j]);
      ll r = min(n, j + a[j] + 1);
      d[l]++;
      d[r]--;
    }
    rep(j, 1, n) d[j] += d[j - 1];
    swap(a, d);
  }
  rep(i, 0, n) cout << a[i] << " ";

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v, vmin, vmax;
  rep(i, n) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  vector<int> org(n, 0);
  vector<int> s = v;

  if (k < 100) {
    rep(j, k) {
      v = s;
      s = org;
      vmin.clear();
      vmax.clear();
      rep(i, n) {
        vmin.push_back(i - v[i]);
        vmax.push_back(i + v[i]);
      }

      vmin.push_back(1000000);
      vmax.push_back(1000000);
      sort(vmin.begin(), vmin.end());
      sort(vmax.begin(), vmax.end());
      // if(vmin[n-1]<0 &&vmax[n-1]>n-1 ){
      //     rep(i,n){
      //         s[i] += (n-1)* (k-j);
      //     }
      //     break;
      // }
      int value = 0;
      int i = 0, mini = 0, maxi = 0;
      // i = max(0,vmin[0]);
      // s = org;
      while (i < n) {
        if (i >= vmin[mini]) {
          value++;
          mini++;
        } else if (i > vmax[maxi]) {
          value--;
          maxi++;
        } else {
          s[i] = value;
          i++;
        }
        // cout << i  <<" " <<   value<< " " << mini << " " <<maxi << endl;
      }
    }
  } else {
    rep(i, n) { s[i] = n; }
  }

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


Error: TLE

Fixed submission:

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v, vmin, vmax;
  rep(i, n) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  vector<int> org(n, 0);
  vector<int> s = v;

  if (k < 1000000) {
    rep(j, k) {
      v = s;
      s = org;
      vmin.clear();
      vmax.clear();
      rep(i, n) {
        vmin.push_back(i - v[i]);
        vmax.push_back(i + v[i]);
      }

      vmin.push_back(1000000);
      vmax.push_back(1000000);
      sort(vmin.begin(), vmin.end());
      sort(vmax.begin(), vmax.end());
      // if(vmin[n-1]<0 &&vmax[n-1]>n-1 ){
      //     rep(i,n){
      //         s[i] += (n-1)* (k-j);
      //     }
      //     break;
      // }
      int value = 0;
      int i = 0, mini = 0, maxi = 0;
      // i = max(0,vmin[0]);
      // s = org;
      while (i < n) {
        if (i >= vmin[mini]) {
          value++;
          mini++;
        } else if (i > vmax[maxi]) {
          value--;
          maxi++;
        } else {
          s[i] = value;
          i++;
        }
        // cout << i  <<" " <<   value<< " " << mini << " " <<maxi << endl;
      }
    }
  } else {
    rep(i, n) { s[i] = n; }
  }

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