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

#include <bits/stdc++.h>

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef vector<cd> vcd;
typedef vector<int> vi;

template <class T> using v2d = vector<vector<T>>;
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 2e5 + 10;

int n, k;
ll a[maxN], b[maxN];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  for1(i, n) { cin >> a[i]; }
  uin(k, 20000000 / n);
  while (k--) {
    fill(b + 1, b + n + 1, 0);
    for1(i, n) {
      int l = max(i - a[i], 1LL), r = min(i + a[i], (ll)n);
      ++b[l];
      if (r < n) {
        --b[r + 1];
      }
    }
    for1(i, n) {
      b[i] += b[i - 1];
      a[i] = b[i];
    }
  }
  for1(i, n) { cout << a[i] << ' '; }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef vector<cd> vcd;
typedef vector<int> vi;

template <class T> using v2d = vector<vector<T>>;
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 10;

int n, k;
ll a[maxN], b[maxN];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  for1(i, n) { cin >> a[i]; }
  uin(k, 20000000 / n);
  while (k--) {
    fill(b + 1, b + n + 1, 0);
    for1(i, n) {
      int l = max(i - a[i], 1LL), r = min(i + a[i], (ll)n);
      ++b[l];
      if (r < n) {
        --b[r + 1];
      }
    }
    for1(i, n) {
      b[i] += b[i - 1];
      a[i] = b[i];
    }
  }
  for1(i, n) { cout << a[i] << ' '; }
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

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

int a[200010], c[200010];

int max(int a, int b) { return a > b ? a : b; }

inline int read() {
  int X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch))
    X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return w ? -X : X;
}

inline void write(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}

inline void writeln(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
  puts("");
}

signed main() {
  int n = read(), k = read();

  for (int i = 1; i <= n; i++)
    a[i] = read();

  for (int j = 1; j <= k; j++) {
    memset(c, 0, sizeof(c));
    for (int i = 1; i <= n; i++) {
      c[max(1, i - a[i])]++;
      c[min(n + 1, i + a[i] + 1)]--;
    }
    int s = 0, f = 1;

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

  for (int i = 1; i <= n; i++)
    write(a[i]), cout << " ";

  puts("");

  return 0;
}

Error: WA

Fixed submission:

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

int a[100010], c[100010];

int max(int a, int b) { return a > b ? a : b; }

inline int read() {
  int X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch))
    X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return w ? -X : X;
}

inline void write(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}

inline void writeln(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
  puts("");
}

signed main() {
  int n = read(), k = read();

  for (int i = 1; i <= n; i++)
    a[i] = read();

  for (int j = 1; j <= k; j++) {
    memset(c, 0, sizeof(c));
    for (int i = 1; i <= n; i++) {
      c[max(1, i - a[i])]++;
      c[min(n + 1, i + a[i] + 1)]--;
    }
    int s = 0, f = 1;

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

  for (int i = 1; i <= n; i++)
    write(a[i]), cout << " ";

  puts("");

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

#include <bits/stdc++.h>
using namespace std;
int A[200100], B[200100];
priority_queue<int, vector<int>, greater<int>> PQ1;
priority_queue<int, vector<int>, less<int>> PQ2;
int main() {
  int N, K;
  cin >> N >> K;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  while (K--) {
    while (!PQ1.empty())
      PQ1.pop();
    for (int i = 0; i < N; i++) {
      PQ1.push(i + A[i]);
      while (PQ1.top() < i)
        PQ1.pop();
      B[i] = (int)(PQ1.size());
    }
    while (!PQ2.empty())
      PQ2.pop();
    for (int i = N - 1; i >= 0; i--) {
      PQ2.push(i - A[i]);
      while (PQ2.top() > i)
        PQ2.pop();
      B[i] += (int)(PQ2.size());
      B[i]--;
    }
    bool OK = true;
    for (int i = 0; i < N; i++) {
      if (B[i] != N)
        OK = false;
      A[i] = B[i];
    }
    if (OK)
      break;
  }
  for (int i = 0; i < N; i++)
    cout << A[i] << " ";
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int A[100100], B[100100];
priority_queue<int, vector<int>, greater<int>> PQ1;
priority_queue<int, vector<int>, less<int>> PQ2;
int main() {
  int N, K;
  cin >> N >> K;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  while (K--) {
    while (!PQ1.empty())
      PQ1.pop();
    for (int i = 0; i < N; i++) {
      PQ1.push(i + A[i]);
      while (PQ1.top() < i)
        PQ1.pop();
      B[i] = (int)(PQ1.size());
    }
    while (!PQ2.empty())
      PQ2.pop();
    for (int i = N - 1; i >= 0; i--) {
      PQ2.push(i - A[i]);
      while (PQ2.top() > i)
        PQ2.pop();
      B[i] += (int)(PQ2.size());
      B[i]--;
    }
    bool OK = true;
    for (int i = 0; i < N; i++) {
      if (B[i] != N)
        OK = false;
      A[i] = B[i];
    }
    if (OK)
      break;
  }
  for (int i = 0; i < N; i++)
    cout << A[i] << " ";
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b);
#define chmin(a, b) a = min(a, b);
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<int> a(200100);
vector<int> b(200100);

int main() {
  int n, k;
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  rep(_, k) {
    rep(i, n) b[i] = 0;
    rep(i, n) {
      int l = max(0, i - a[i]), r = min(n + 3, i + a[i]);
      b[l] += 1;
      b[r + 1] -= 1;
    }
    int now = 0;
    rep(i, n) {
      now += b[i];
      a[i] = now;
    }
    int m = 1001001001;
    rep(i, n) m = min(a[i], m);
    if (m == n)
      break;
  }
  rep(i, n) cout << a[i] << (i == n - 1 ? '\\n' : ' ');
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b);
#define chmin(a, b) a = min(a, b);
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<int> a(200100);
vector<int> b(200100);

int main() {
  int n, k;
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  rep(_, k) {
    rep(i, n) b[i] = 0;
    rep(i, n) {
      int l = max(0, i - a[i]), r = min(n - 1, i + a[i]);
      for (int x = l; x <= r; x++) {
        b[x] += 1;
      }
    }
    swap(a, b);
    int m = 1001001001;
    rep(i, n) m = min(a[i], m);
    if (m == n)
      break;
  }
  rep(i, n) cout << a[i] << (i == n - 1 ? '\\n' : ' ');
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n, 0);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int it = 0;
  while (k--) {
    vector<int> b(n + 1, 0);
    for (int i = 0; i < n; i++) {
      b[max(0, i - a[i])]++;
      b[min(n, i + a[i] + 1)]--;
    }
    a[0] = b[0];
    for (int i = 1; i < n; i++) {
      b[i] += b[i - 1];
      a[i] = b[i];
    }
    bool good = true;
    for (int i = 0; i < n; i++)
      if (a[i] != n)
        good = false;
    if (good) {
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << ' ';
  }
  cout << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n, 0);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int it = 0;
  while (k--) {
    vector<int> b(n + 1, 0);
    for (int i = 0; i < n; i++) {
      b[max(0, i - a[i])]++;
      b[min(n, i + a[i] + 1)]--;
    }
    for (int i = 1; i < n; i++) {
      b[i] += b[i - 1];
    }
    for (int i = 0; i < n; i++) {
      a[i] = b[i];
    }
    bool good = true;
    for (int i = 0; i < n; i++)
      if (a[i] != n + 1)
        good = false;
    if (good) {
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << ' ';
  }
  cout << '\\n';
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define bug(x) cout << "zdongdebug1: " << x << endl;
#define bug2(x, y) cout << "zdongdebug2: " << x << " " << y << endl;
#define bug3(x, y, z)                                                          \\
  cout << "zdongdebug3: " << x << " " << y << " " << z << endl;
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int mod = 1000000007;

int n, m;
int a[maxn], b[maxn];

bool f() {
  bool sign = 0;
  for (int i = 1; i <= n; i++) {
    b[i] = 0;
    if (a[i] < n)
      sign = 1;
  }
  if (!sign) {
    return true;
  }
  for (int i = 1; i <= n; i++) {
    int l = i - a[i];
    int r = i + a[i] + 1;
    l = max(l, 1);
    r = min(r, n + 1);
    b[l]++;
    b[r]--;
    a[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    a[i] = a[i - 1] + b[i];
  }
  return false;
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  // freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= m; i++) {
    if (f()) {
      break;
    }
  }
  for (int i = 1; i < n; i++)
    cout << a[i] << " ";
  cout << a[n] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define bug(x) cout << "zdongdebug1: " << x << endl;
#define bug2(x, y) cout << "zdongdebug2: " << x << " " << y << endl;
#define bug3(x, y, z)                                                          \\
  cout << "zdongdebug3: " << x << " " << y << " " << z << endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;

int n, m;
int a[maxn], b[maxn];

bool f() {
  bool sign = 0;
  for (int i = 1; i <= n; i++) {
    b[i] = 0;
    if (a[i] < n)
      sign = 1;
  }
  if (!sign) {
    return true;
  }
  for (int i = 1; i <= n; i++) {
    int l = i - a[i];
    int r = i + a[i] + 1;
    l = max(l, 1);
    r = min(r, n + 1);
    b[l]++;
    b[r]--;
    a[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    a[i] = a[i - 1] + b[i];
  }
  return false;
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  // freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= m; i++) {
    if (f()) {
      break;
    }
  }
  for (int i = 1; i < n; i++)
    cout << a[i] << " ";
  cout << a[n] << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define inf 1000000007

using namespace std;

typedef long long ll;

int k, n, a[200005], b0[200005], b1[200005];

void add(int *b, int i, int v) {
  while (i <= n) {
    b[i] += v;
    i += (i & (-i));
  }
}

int sum(int *b, int i) {
  ll s = 0;
  while (i > 0) {
    s += b[i];
    i -= (i & (-i));
  }
  return s;
}

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int p = 1;
  while (k--) {
    int v = 0;
    for (int i = 1; i <= n; i++) {
      int l = max(1, i - a[i]), r = min(n, i + a[i]);
      add(b0, l, -1 * (l - 1));
      add(b1, l, 1);
      add(b0, r + 1, 1 * r);
      add(b1, r + 1, -1);
    }
    for (int i = 1; i <= n; i++) {
      a[i] = (sum(b0, i) + sum(b1, i) * i) -
             (sum(b0, i - 1) + sum(b1, i - 1) * (i - 1));
      if (a[i] == n)
        v++;
    }
    if (v == n) {
      p = 0;
      break;
    }
    memset(b0, 0, sizeof(b0));
    memset(b1, 0, sizeof(b1));
  }
  if (p == 0) {
    for (int i = 1; i <= n; i++)
      printf("%d%c", n, i == n ? '\\n' : ' ');
  } else {
    for (int i = 1; i <= n; i++)
      printf("%d%c", a[i], i == n ? '\\n' : ' ');
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define inf 1000000007

using namespace std;

typedef long long ll;

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

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int p = 1;
  while (k--) {
    int v = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = max(1, i - a[i]); j <= min(n, i + a[i]); j++) {
        b[j]++;
        if (b[j] == n) {
          v++;
        }
      }
    }
    if (v == n) {
      p = 0;
      break;
    }
    for (int i = 1; i <= n; i++) {
      a[i] = b[i];
      b[i] = 0;
    }
  }
  if (p == 0) {
    for (int i = 1; i <= n; i++)
      printf("%d%c", n, i == n ? '\\n' : ' ');
  } else {
    for (int i = 1; i <= n; i++)
      printf("%d%c", a[i], i == n ? '\\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> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < K; i++) {
    vector<int> B(N, 0);
    for (int j = 0; j < N; j++) {
      B.at(max(0, j - A.at(j)))++;
      if (j + A.at(j) + 1 <= N - 1)
        B.at(j + A.at(j) + 1)--;
    }
    int cnt = 0;
    for (int j = 1; j < N; j++) {
      B.at(j) += B.at(j - 1);
      if (B.at(j) == N)
        cnt++;
    }
    if (B.at(0) == N)
      cnt++;
    A = B;
    if (cnt == N)
      break;
  }
  for (int i = 0; i < N; i++) {
    if (i)
      cout << ' ';
    cout << A.at(i);
  }
  cout << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, K, a;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < K; i++) {
    vector<int> B(N, 0);
    for (int j = 0; j < N; j++) {
      B.at(max(0, j - A.at(j)))++;
      if (j + A.at(j) + 1 <= N - 1)
        B.at(j + A.at(j) + 1)--;
    }
    int cnt = 0;
    for (int j = 1; j < N; j++) {
      B.at(j) += B.at(j - 1);
      if (B.at(j) == N)
        cnt++;
    }
    A = B;
    if (cnt == N)
      break;
  }
  for (int i = 0; i < N; i++) {
    if (i)
      cout << ' ';
    cout << A.at(i);
  }
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int n, k, x, y, z;
int a[200000];
int b[200000];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  for (int j = 0; j < k; j++) {
    for (int i = 0; i < n; i++)
      b[i] = 0;
    for (int i = 0; i < n; i++) {
      x = i - a[i];
      y = i + a[i];
      if (x < 0)
        x = 0;
      b[x]++;
      y++;
      if (y < n)
        b[y]--;
    }
    for (int i = 1; i < n; i++) {
      b[i] += b[i - 1];
    }
    for (int i = 0; i < n; i++) {
      a[i] = b[i];
    }
    z = 1;
    for (int i = 0; i < n; i++) {
      if (a[i] < n)
        z = 0;
    }
    if (z)
      break;
  }
  for (int i = 0; i < n; i++) {
    if (i < n - 1)
      printf("%d ", a[i]);
    else
      printf("%d\\n", a[i]);
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>
int n, k, x, y;
int a[200000];
int b[200000];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  for (int j = 0; j < k; j++) {
    for (int i = 0; i < n; i++)
      b[i] = 0;
    for (int i = 0; i < n; i++) {
      x = i - a[i];
      y = i + a[i];
      if (x < 0)
        x = 0;
      b[x]++;
      y++;
      if (y < n)
        b[y]--;
    }
    for (int i = 1; i < n; i++) {
      b[i] += b[i - 1];
    }
    for (int i = 0; i < n; i++) {
      a[i] = b[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (i < n - 1)
      printf("%d ", a[i]);
    else
      printf("%d\\n", a[i]);
  }
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

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);
    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: 0

Fixed submission:

#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

vector<int> G[1001001];

int main() {
  ll n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  rep(i, k) {
    vector<int> nex(n);
    rep(j, n) {
      if (j - a[j] < 0) {
        rep(h, j + a[j] + 1) nex[h]++;
      } else {
        repl(h, j - a[j], j + a[j] + 1) nex[h]++;
      }
    }
    rep(j, n) a[j] = nex[j];
    rep(j, n) {
      if (a[j] == n) {
        if (i == k - 1) {
          rep(h, n - 1) { cout << a[h] << " "; }
          cout << a[n - 1] << endl;
          return 0;
        } else {
          rep(h, n - 1) cout << n << " ";
          cout << n << endl;
          return 0;
        }
      }
    }
  }
  rep(i, n - 1) { cout << a[i] << " "; }
  cout << a[n - 1] << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
#define INF (1e9)

int main() {
  int N, K;
  cin >> N >> K;
  vi A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  while (K--) {
    vi B(N + 1);
    for (int i = 0; i < N; i++) {
      B[max(0, i - A[i])]++;
      B[min(N, i + A[i] + 1)]--;
    }
    int s = 0;
    bool f = true;
    for (int i = 0; i < N; i++) {
      s += B[i];
      A[i] = s;
      f &= s == N;
    }
    if (f)
      break;
  }

  for (int i = 0; i < N; i++) {
    cout << A[i] << ' ';
  }
  cout << endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
#define INF (1e9)

int main() {
  int N, K;
  cin >> N >> K;
  vi A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  while (K--) {
    vi B(N + 1);
    for (int i = 0; i < N; i++) {
      B[max(0, i - A[i])]++;
      B[min(N, i + A[i]) + 1]--;
    }
    int s = 0;
    bool f = true;
    for (int i = 0; i < N; i++) {
      s += B[i];
      A[i] = s;
      f &= s == N;
    }
    if (f)
      break;
  }

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

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

#define ll long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
// map<int, int>::iterator itr;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int arr[n + 1], brr[n + 1];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      brr[i] = 0;
    }
    int count = 0;
    while (k--) {
      for (int i = 0; i < n; i++) {
        int p = max(0, i - arr[i]);
        brr[p] += 1;
        p = min(n - 1, i + arr[i]);
        brr[p + 1] -= 1;
      }
      for (int i = 1; i < n; i++) {
        brr[i] += brr[i - 1];
      }
      int f = 1;
      for (int i = 0; i < n; i++) {
        arr[i] = brr[i];
        brr[i] = 0;
        if (arr[i] != n)
          f = 0;
      }
      if (f == 1)
        break;
    }
    for (int i = 0; i < n; i++) {
      cout << arr[i] << " ";
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

#define ll long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
// map<int, int>::iterator itr;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int arr[n], brr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      brr[i] = 0;
    }
    int count = 0;
    while (k--) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          if (abs(i - j) <= arr[j]) {
            brr[i]++;
          }
        }
      }
      int f = 1;
      for (int i = 0; i < n; i++) {
        arr[i] = brr[i];
        brr[i] = 0;
        if (arr[i] != n)
          f = 0;
      }
      if (f == 1)
        break;
    }
    for (int i = 0; i < n; i++) {
      cout << arr[i] << " ";
    }
  }
  return 0;
}