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

#include <bits/stdc++.h>
#define repp(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647; // int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
// ミョ(-ω- ?)
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n + 2, 0);
  repp(i, 1, n + 1) cin >> a[i];
  if (k >= (n + 1) / 2 + 1) {
    k = (n + 1) / 2 + 1;
    rep(i, n) cout << n << " ";
    cout << endl;
    return 0;
  }
  rep(i, k) {
    vector<ll> table(n + 2, 0);
    repp(j, 1, n + 1) {
      table[max(0LL, j - a[j])]++;
      table[min(n + 1, j + (a[j] + 1))]--;
    }
    repp(j, 1, n + 2) {
      table[j] = table[j] + table[j - 1];
      a[j] = table[j];
    }
  }
  repp(i, 1, n + 1) cout << a[i] << " ";
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define repp(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647; // int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
// ミョ(-ω- ?)
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n + 2, 0);
  repp(i, 1, n + 1) cin >> a[i];
  if (k >= (n + 1) / 2 + 1)
    k = (n + 1) / 2 + 1;
  rep(i, k) {
    vector<ll> table(n + 2, 0);
    repp(j, 1, n + 1) {
      table[max(0LL, j - a[j])]++;
      table[min(n + 1, j + (a[j] + 1))]--;
    }
    repp(j, 1, n + 2) {
      table[j] = table[j] + table[j - 1];
      a[j] = table[j];
    }
  }
  repp(i, 1, n + 1) cout << a[i] << " ";
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

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

#define REP(i, n) for (ll i = 0; i < (ll)(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;
  cin >> n >> k;
  // vector<int> a(100005);
  vector<int> a(200005);
  REP(i, n) cin >> a[i];
  // vector<int> b(100005, 0);
  vector<int> b(200005, 0);
  REP(_, min(k, 42)) {
    vector<int> b(200005, 0);
    REP(i, n) {
      int l = max(0, (int)i - a[i]);
      int 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 (ll i = 0; i < (ll)(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;
  cin >> n >> k;
  vector<int> a(100005);
  REP(i, n) cin >> a[i];
  vector<int> b(100005, 0);
  REP(_, min(k, 42)) {
    vector<int> b(100005, 0);
    REP(i, n) {
      int l = max(0, (int)i - a[i]);
      int 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] << " ";
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

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

#define REP(i, n) for (ll i = 0; i < (ll)(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;
  cin >> n >> k;
  // vector<int> a(100005);
  vector<int> a(200005);
  REP(i, n) cin >> a[i];
  // vector<int> b(100005, 0);
  vector<int> b(200005, 0);
  REP(_, min(k, 42)) {
    vector<int> b(200005, 0);
    REP(i, n) {
      int l = max(0, (int)i - a[i]);
      int 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] << " ";
  cout << endl;
}


Error: WA

Fixed submission:

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

#define REP(i, n) for (ll i = 0; i < (ll)(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;
  cin >> n >> k;
  // vector<int> a(100005);
  vector<int> a(200005);
  REP(i, n) cin >> a[i];
  // vector<int> b(100005, 0);
  vector<int> b(200005, 0);
  REP(_, min(k, 42)) {
    vector<int> b(100005, 0);
    REP(i, n) {
      int l = max(0, (int)i - a[i]);
      int 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

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> tasu(n);
  vector<int> h(n);

  rep(i, n) {
    cin >> a[i];
    tasu[i];
    h[i];
  }
  if (n <= k) {
    rep(i, n) cout << n << " ";
    cout << endl;
    return 0;
  }
  rep(t, k) {
    tasu = h;
    rep(i, n) {
      tasu[max(0, i - a[i])]++;
      int tasuin = i + a[i] + 1;
      if (tasuin < n)
        tasu[tasuin]--;
    }
    ll now = 0;
    bool finish = true;
    rep(i, n - 1) { tasu[i + 1] += tasu[i]; }
    if (tasu == a)
      break;
    a = tasu;
  }
  rep(i, n) cout << a[i] << " ";
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> tasu(n);
  vector<int> h(n);

  rep(i, n) {
    cin >> a[i];
    vector<ll> tasu(n);
    vector<ll> h(n);
  }
  if (n <= k) {
    rep(i, n) cout << n << " ";
    cout << endl;
    return 0;
  }
  rep(t, k) {
    tasu = h;
    rep(i, n) {
      tasu[max(0, i - a[i])]++;
      int tasuin = i + a[i] + 1;
      if (tasuin < n)
        tasu[tasuin]--;
    }
    ll now = 0;
    bool finish = true;
    rep(i, n - 1) { tasu[i + 1] += tasu[i]; }
    if (tasu == a)
      break;
    a = tasu;
  }
  rep(i, n) cout << a[i] << " ";
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

void operation(vector<int> &a) {
  vector<int> b(a.size(), 0);
  for (int i = 0; i < (long long)a.size(); i++) {
    int start = i - a[i];
    int end = i + a[i] + 1;
    if (start < 0)
      start = 0;
    b[start]++;
    if (end < (long long)a.size())
      b[end]--;
  }

  for (int i = 1; i < (long long)a.size(); i++) {
    b[i] += b[i - 1];
  }

  a = b;
}

signed main() {
  cin.tie(0);
  ios::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++) {
    operation(a);
    if (a == vector<int>(n, n))
      break;
  }

  for (auto &&ai : a) {
    cout << ai << " ";
  }
  cout << endl;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

void operation(vector<int> &a) {
  vector<int> b(a.size(), 0);
  for (int i = 0; i < (long long)a.size(); i++) {
    int start = i - a[i];
    int end = i + a[i] + 1;
    if (start < 0)
      start = 0;
    b[start]++;
    if (end <= (long long)a.size())
      b[end]--;
  }

  for (int i = 1; i < (long long)a.size(); i++) {
    b[i] += b[i - 1];
  }

  a = b;
}

signed main() {
  cin.tie(0);
  ios::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++) {
    operation(a);
    if (a == vector<int>(n, n))
      break;
  }

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

#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> task(n + 1);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  if (k > 1000) {
    for (int i = 0; i < n; i++)
      cout << n << " ";
    cout << endl;
    return 0;
  }

  for (int i = 0; i < k; i++) {
    for (int j = 0; j <= n; j++) {
      task[j] = 0;
    }
    int temp = 0;
    for (int now = 0; now < n; now++) {
      task[max(0, now - a[now])] += 1;
      task[min(n, now + a[now] + 1)] -= 1;
    }
    for (int now = 0; now < n; now++) {
      temp += task[now];
      a[now] = temp;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> task(n + 1);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  if (n * 4 <= k) {
    for (int i = 0; i < n; i++)
      cout << n << " ";
    cout << endl;
    return 0;
  }

  for (int i = 0; i < k; i++) {
    for (int j = 0; j <= n; j++) {
      task[j] = 0;
    }
    int temp = 0;
    for (int now = 0; now < n; now++) {
      task[max(0, now - a[now])] += 1;
      task[min(n, now + a[now] + 1)] -= 1;
    }
    for (int now = 0; now < n; now++) {
      temp += task[now];
      a[now] = temp;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void print(vector<int> x) {
  int n;
  for (n = 1; n < x.size() - 1; n++) {
    cout << x.at(n) << " ";
  }
  cout << x.at(n) << endl;
}

void clean(vector<int> &x) {
  for (int n = 0; n < x.size(); n++) {
    x.at(n) = 0;
  }
}

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

  vector<int> A(N + 1);
  vector<int> B(N + 1);

  for (int n = 1; n <= N; n++) {
    cin >> A.at(n);
  }

  // print(A);

  for (int k = 0; k < K; k++) {
    bool is_satu = true;
    clean(B);
    for (int n = 1; n <= N; n++) {
      int v = A.at(n);
      int spos = max(1, n - v);
      int epos = min(N, n + v);
      // cout << v << " " << spos << " " << epos << endl;
      B.at(spos)++;
      if (epos + 1 <= N) {
        B.at(epos + 1)--;
      }
    }
    // print(B);
    for (int n = 1; n <= N; n++) {
      B.at(n) += B.at(n - 1);
      if (B.at(n) != N) {
        is_satu = false;
      }
    }
    A = B;
    if (is_satu) {
      break;
    }
  }
  print(A);
}


Error: TLE

Fixed submission:

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

void print(vector<int> x) {
  int n;
  for (n = 1; n < x.size() - 1; n++) {
    cout << x.at(n) << " ";
  }
  cout << x.at(n) << endl;
}

void clean(vector<int> &x) {
  for (int n = 0; n < x.size(); n++) {
    x.at(n) = 0;
  }
}

bool checkN(vector<int> &x, int N) {
  for (int n = 1; n < x.size(); n++) {
    if (x.at(n) != N) {
      return false;
    }
  }
  return true;
}

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

  vector<int> A(N + 1);
  vector<int> B(N + 1);

  for (int n = 1; n <= N; n++) {
    cin >> A.at(n);
  }

  // print(A);

  for (int k = 0; k < K; k++) {
    clean(B);
    for (int n = 1; n <= N; n++) {
      int v = A.at(n);
      int spos = n - v;
      int epos = n + v;
      if (spos <= 1) {
        spos = 1;
      }
      if (epos >= N) {
        epos = N;
      }
      while (spos <= epos) {
        B.at(spos) += 1;
        spos++;
      }
    }
    A = B;
    if (checkN(A, N)) {
      break;
    }
  }
  print(A);
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, k, sum, a[200005], b[200005];
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  if (k > 50) {
    rep(i, n) { cout << n << " \\n"[i == n - 1]; }
    return 0;
  } else {
    rep(i, k) {
      memset(b, 0, sizeof(b));
      rep(j, n) {
        ++b[max(0, j - a[j])];
        --b[min(n, j + a[j] + 1)];
      }
      sum = 0;
      rep(j, n) {
        sum += b[j];
        a[j] = sum;
      }
    }
    rep(i, n) { cout << a[i] << " \\n"[i == n - 1]; }
    return 0;
  }
}

Error: 0

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  int dp[n + 5][k + 5];
  rep(i, n) dp[i][0] = 0;
  rep(i, n) cin >> dp[i][1];
  if (k > 50) {
    for (int i = 0; i < n; i++) {
      cout << n << " \\n"[i == n - 1];
    }
    return 0;
  } else {
    for (int j = 1; j < k + 1; ++j) {
      bool ok = true;
      rep(i, n) {
        dp[i][j + 1] = dp[i][j];
        if (dp[i][j + 1] == n)
          continue;
        if (dp[i][j] == 0)
          dp[i][j + 1] = 1;
        rep(l, n) {
          if (l == i)
            continue;
          if (abs(i - l) <= dp[l][j] && abs(i - l) > dp[l][j - 1]) {
            ++dp[i][j + 1];
          }
        }
      }
      rep(i, n) {
        if (dp[i][j + 1] != n)
          ok = false;
      }
      if (ok) {
        rep(i, n - 1) { cout << dp[i][j + 1] << " "; }
        cout << dp[n - 1][j + 1] << "\\n";
        return 0;
      }
    }
    rep(i, n - 1) { cout << dp[i][k + 1] << " "; }
    cout << dp[n - 1][k + 1] << "\\n";
    return 0;
  }
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n, k;
  cin >> n >> k;
  int a[200001];
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  bool z = 0;
  while (k--) {
    int r[200001] = {0};
    int l[200001] = {0};
    for (int i = 1; i <= n; i++) {
      r[max(i - a[i], 1)]++;
      l[min(n, i + a[i])]++;
    }
    if (r[1] == n && l[n] == n) {
      z = 1;
      break;
    }
    int j = 0;
    for (int i = 1; i <= n; i++) {
      j += r[i];
      a[i] = j;
      j -= l[i];
    }
  }
  if (z) {
    for (int i = 1; i <= n; i++)
      cout << n << ' ';
  } else {
    for (int i = 1; i <= n; i++)
      cout << a[i] << ' ';
  }
  cout << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n, k;
  cin >> n >> k;
  int a[200001];
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  while (k--) {
    int r[200001] = {0};
    int l[200001] = {0};
    for (int i = 1; i <= n; i++) {
      r[max(i - a[i], 1)]++;
      l[min(n, i + a[i])]++;
    }
    int j = 0;
    for (int i = 1; i <= n; i++) {
      j += r[i];
      a[i] = j;
      j -= l[i];
    }
  }
  for (int i = 1; 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;
#define REP(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n, 0);
  REP(i, n) cin >> a.at(i);

  REP(i, k) {
    vector<int> b(n + 1, 0), c(n + 1, 0);
    REP(j, n) {
      b.at(max(0, j - a.at(j)))++;
      b.at(min(n, j + a.at(j) + 1))--;
    }
    REP(j, n) c.at(j + 1) = c.at(j) + b.at(j);
    REP(j, n) a.at(j) = c.at(j + 1);

    bool f = 1;
    REP(j, n) if (a.at(j) != n) f = 0;
    if (f)
      break;
  }

  REP(i, n) cout << a.at(i) << " ";
}

Error: TLE

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n, 0);
  REP(i, n) cin >> a.at(i);

  REP(i, k) {
    vector<int> b(n, 0);
    REP(j, n) {
      for (int k = -a.at(j); k <= a.at(j); k++) {
        int now = j + k;
        if (now >= 0 && now < n)
          b.at(now)++;
      }
    }
    REP(j, n) a.at(j) = b.at(j);

    bool f = 1;
    REP(j, n) if (a.at(j) != n) f = 0;
    if (f)
      break;
  }

  REP(i, n) cout << a.at(i) << " ";
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rept(i, j, n) for (int i = (j); i < (n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    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(i, min(1000, k)) {

    vector<int> plus(n), minus(n);
    rep(j, n) {
      int s = max(0, j - A[j]), t = min(n - 1, j + A[j]);
      plus[s]++;
      minus[t]++;
    }
    int cnt = 0;
    rep(j, n) {
      cnt += plus[j];
      A[j] = cnt;
      cnt -= minus[j];
    }
  }
  rep(i, n) cout << A[i] << " ";
  cout << ln;
}


Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rept(i, j, n) for (int i = (j); i < (n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    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(i, min(5000, k)) {
    vector<int> imos(n + 1);
    rep(j, n) {
      int s = max(0, j - A[j]), g = min(n, j + A[j] + 1);
      imos[s]++;
      imos[g]--;
    }
    rep(j, n) {
      if (j)
        A[j] = A[j - 1];
      else
        A[j] = 0;
      A[j] += imos[j];
    }
  }
  rep(i, n) cout << A[i] << " ";
  cout << ln;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> c(n, n);
  rep(i, n) { cin >> a[i]; }
  rep(j, k) {
    vector<int> d(n + 1);
    rep(i, n) {
      d[max(i - a[i], 0)]++;
      d[min(i + a[i] + 1, n)]--;
    }
    vector<int> e(n, d[0]);
    rep(i, n - 1) { e[i + 1] = e[i] + d[i + 1]; }
    a = e;
    if (c == e) {
      break;
    }
  }
  rep(i, n - 1) { cout << a[i] << ' '; }
  cout << a[n - 1] << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> c(n, n);
  rep(i, n) { cin >> a[i]; }
  rep(j, k) {
    vector<int> d(n + 1);
    rep(i, n) {
      d[max(i - a[i], 0)]++;
      d[min(i + a[i] + 1, n)]--;
    }
    vector<int> e(n, d[0]);
    rep(i, n) { e[i + 1] = e[i] + d[i + 1]; }
    a = e;
    if (c == e) {
      break;
    }
  }
  rep(i, n - 1) { cout << a[i] << ' '; }
  cout << a[n - 1] << endl;
  return 0;
}