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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vout(x) rep(i, x.size()) cout << x[i] << " "
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
  int n, k;
  cin >> n >> k;
  vint a(n);
  rep(i, n) cin >> a[i];
  rep(i, k) {
    vint c(n + 1, 0);
    rep(j, n) {
      c[max(j - a[j], 0)]++;
      c[min(j + a[j] + 1, n)]--;
    }
    vint a_tmp(n);
    a_tmp[0] = c[0];
    REP(i, n) a_tmp[i] = a_tmp[i - 1] + c[i];
    swap(a_tmp, a);
    bool ok = true;
    rep(i, n - 1) {
      if (a[i] != a[i + 1])
        ok = false;
    }
    if (ok && a[0] == n)
      break;
  }
  rep(i, n) cout << a[i] << " ";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vout(x) rep(i, x.size()) cout << x[i] << " "
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
  int n, k;
  cin >> n >> k;
  vint a(n);
  rep(i, n) cin >> a[i];
  rep(i, k) {
    vint c(n + 1, 0);
    rep(j, n) {
      c[max(j - a[j], 0)]++;
      c[min(j + a[j] + 1, n)]--;
    }
    vint a_tmp(n);
    a_tmp[0] = c[0];
    REP(i, n) a_tmp[i] = a_tmp[i - 1] + c[i];
    swap(a_tmp, a);
    bool ok = true;
    // rep(i,n-1) {
    //     if (a[i] != a[i+1]) ok = false;
    // }
    // if (ok) break;
  }
  rep(i, n) cout << a[i] << " ";
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto &i : a)
    cin >> i;
  for (int i = 0; i < k; i++) {
    vector<int> b(n + 1, 0);
    for (int j = 0; j < n; j++) {
      int l = max(0, j - a[j]);
      int r = min(n - 1, j + a[j]);
      r++;
      b[l]++;
      b[r]--;
    }
    bool flg = true;
    for (int j = 0; j < n; j++) {
      b[j + 1] += b[j];
      a[j] = b[j];
      // cout<<a[j]<<' ';
      if (a[j] != n)
        flg = false;
    }
    if (flg)
      break;
    // cout<<endl;
  }
  for (auto &i : a)
    cout << i << ' ';
  cout << endl;
}

Error: WA

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n, 0);
  for (auto &i : a)
    cin >> i;
  for (int i = 0; i < k; i++) {
    vector<int> b(n + 1, 0);
    for (int j = 0; j < n; j++) {
      int l = max(0, j - a[j]);
      int r = min(n, j + a[j]);
      r++;
      b[l]++;
      b[r]--;
    }
    bool flg = true;
    for (int j = 0; j < n; j++) {
      b[j + 1] += b[j];
      a[j] = b[j];
      // cout<<a[j]<<' ';
      if (a[j] != n)
        flg = false;
    }
    if (flg)
      break;
    // cout<<endl;
  }
  for (auto &i : a)
    cout << i << ' ';
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
int n, k;
int it[200001];
int pre[200001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> it[i];
  }
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n + 1; j++) {
      pre[j] = 0;
    }
    for (int j = 0; j < n; j++) {
      pre[max(j - it[j], 0)] += 1;
      pre[min(j + it[j] + 1, n)] -= 1;
    }
    int x = pre[0];
    int st = 0;
    int su = 0;
    for (int j = 0; j < n; j++) {
      su += pre[j];
      if (it[j] != x) {
        st = 1;
      }
      it[j] = su;
    }
    if (st == 0) {
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << it[i] << " ";
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
int n, k;
int it[200001];
int pre[200001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> it[i];
  }
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n + 1; j++) {
      pre[j] = 0;
    }
    for (int j = 0; j < n; j++) {
      pre[max(j - it[j], 0)] += 1;
      pre[min(j + it[j] + 1, n)] -= 1;
    }
    int x = pre[0];
    int st = 0;
    int su = 0;
    for (int j = 0; j < n; j++) {
      su += pre[j];
      if (su + j < n - 1 or su - j > 0) {
        st = 1;
      }
      it[j] = su;
    }
    if (st == 0) {
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << it[i] << " ";
  }
  cout << 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;
using ll = long long;
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;
}
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }
  rep(i, k) {
    bool end_flag = true;
    vector<int> s(n, 0); // a[i] = s[0] + s[1] + ... + s[i]
    rep(i, n) {
      s[max(0, i - a[i])]++;
      if (i + a[i] + 1 < n)
        s[i + a[i] + 1]--;
    }
    a[0] = s[0];
    rep(i, n - 1) { a[i + 1] = a[i] + s[i + 1]; }
    rep(i, n) if (a[i] != n) end_flag = false;
    if (end_flag)
      break;
  }
  rep(i, n) { cout << a[i] << endl; }
}


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;
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;
}
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }
  rep(i, k) {
    bool end_flag = true;
    vector<int> s(n, 0); // a[i] = s[0] + s[1] + ... + s[i]
    rep(i, n) {
      s[max(0, i - a[i])]++;
      if (i + a[i] + 1 < n)
        s[i + a[i] + 1]--;
    }
    a[0] = s[0];
    rep(i, n - 1) { a[i + 1] = a[i] + s[i + 1]; }
    rep(i, n) if (a[i + 1] != n) end_flag = false;
    if (end_flag)
      break;
  }
  rep(i, n) { cout << a[i] << endl; }
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[200005], b[200005];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  if (k > 50) {
    for (int i = 0; i < n; ++i) {
      cout << n << ' ';
    }
    cout << '\\n';
    return 0;
  }
  for (int i = 0; i < k; ++i) {
    memset(b, 0, sizeof(b));
    for (int i = 0; i < n; ++i) {
      int l = max(0, i - a[i]);
      int r = min(n - 1, i + a[i]);
      b[l]++;
      if (r + 1 < n) {
        b[r + 1]--;
      }
    }
    for (int i = 1; i < n; ++i) {
      b[i] += b[i - 1];
    }
    for (int i = 0; i < n; ++i) {
      a[i] = b[i];
    }
  }
  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;
int n, k;
int a[200005], b[200005];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < k; ++i) {
    memset(b, 0, sizeof(b));
    for (int i = 0; i < n; ++i) {
      int l = max(0, i - a[i]);
      int r = min(n - 1, i + a[i]);
      b[l]++;
      if (r + 1 < n) {
        b[r + 1]--;
      }
    }
    for (int i = 1; i < n; ++i) {
      b[i] += b[i - 1];
    }
    for (int i = 0; i < n; ++i) {
      a[i] = b[i];
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << a[i] << ' ';
  }
  cout << '\\n';
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;

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

  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  vector<ll> B(N, 0);
  vector<ll> S(N, 0);
  vector<ll> E(N, 0);

  for (ll k = 0; k < K; k++) {
    bool flg = true;
    rep(i, N) {
      if (A[i] != N) {
        flg = false;
      }
    }
    // cout << "flg:" << flg << endl;
    if (flg)
      break;

    rep(i, N) {
      B[i] = 0;
      S[i] = 0;
      E[i] = 0;
    }

    for (ll i = 0; i < N; i++) {
      ll s = max(0LL, i - A[i]);
      ll e = min(i + A[i], N - 1);
      S[s]++;
      E[e]++;
    }

    // cout << "S: ";
    // rep(i, N) { cout << S[i] << " "; }
    // cout << endl;

    // cout << "E: ";
    // rep(i, N) { cout << E[i] << " "; }
    // cout << endl;

    ll now = 0LL;
    for (ll i = 0; i < N; i++) {
      now += S[i];
      B[i] = now;
      now -= E[i];
    }
    // rep(i, N) cout << B[i] << " ";
    // cout << endl;

    rep(i, N) A[i] = B[i];
  }

  rep(i, N) cout << A[i] << " ";
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;

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

  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  vector<ll> B(N, 0);
  vector<ll> S(N, 0);
  vector<ll> E(N, 0);

  for (ll k = 0; k < K; k++) {
    rep(i, N) {
      B[i] = 0;
      S[i] = 0;
      E[i] = 0;
    }

    for (ll i = 0; i < N; i++) {
      ll s = max(0LL, i - A[i]);
      ll e = min(i + A[i], N - 1);
      // cout << "s:" << s << ", e:" << e << endl;
      S[s]++;
      E[e]++;
    }

    // cout << "S: ";
    // rep(i, N) { cout << S[i] << " "; }
    // cout << endl;

    // cout << "E: ";
    // rep(i, N) { cout << E[i] << " "; }
    // cout << endl;

    ll now = 0LL;
    for (ll i = 0; i < N; i++) {
      now += S[i];
      B[i] = now;
      now -= E[i];
    }
    // rep(i, N) cout << B[i] << " ";
    // cout << endl;

    rep(i, N) A[i] = B[i];
  }

  rep(i, N) cout << A[i] << " ";
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<int> as(N);
  for (int i = 0; i < N; i++)
    cin >> as.at(i);

  while (K--) {
    vector<int> nas(N, 0);
    int numnax = 0;
    for (int i = 0; i < N; i++) {
      int l = max(0, i - as.at(i));
      int r = min(N - 1, i + as.at(i));
      nas.at(l)++;
      if (r + 1 < N)
        nas.at(r + 1)--;
    }
    if (nas.at(0) == N)
      numnax++;
    for (int i = 1; i < N; i++) {
      nas.at(i) += nas.at(i - 1);
      if (nas.at(i) == N)
        numnax++;
    }
    as = nas;
    if (numnax == N)
      break;
  }
  for (int i = 0; i < N; i++) {
    if (i != N - 1)
      cout << as.at(i) << ' ';
    else
      cout << as.at(i) << '\\n';
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<int> as(N);
  for (int i = 0; i < N; i++)
    cin >> as.at(i);

  vector<int> nax(N, 0);
  int numnax = 0;
  while (K--) {
    vector<int> nas = nax;
    for (int i = 0; i < N; i++) {
      if (nax.at(i) == N)
        continue;
      for (int j = max(0, i - as.at(i)); j <= i + as.at(i) && j < N; j++) {
        if (nax.at(j) == N)
          continue;
        nas.at(j)++;
        if (nas.at(j) == N) {
          nax.at(j) = N;
          numnax++;
        }
      }
    }
    as = nas;
    if (numnax == N)
      break;
  }
  for (int i = 0; i < N; i++) {
    if (i != N - 1)
      cout << as.at(i) << ' ';
    else
      cout << as.at(i) << '\\n';
  }

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

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

#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (int(i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for (int(i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
// constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9 + 7;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N, 0);
  priority_queue<int, vector<int>, greater<int>> left;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      right, mi;
  REP(i, N) { cin >> A[i]; }

  int loop = min(50, K);
  while (loop--) {
    REP(i, N) { mi.push({i - A[i], i}); }
    vector<int> B(N);
    REP(i, N) {
      while (!mi.empty() && mi.top().first <= i) {
        auto [x, id] = mi.top();
        mi.pop();
        if (x <= i) {
          left.push(id + A[id]);
        } else {
          right.push({id - A[id], id});
        }
      }
      while (!right.empty() && right.top().first <= i) {
        auto [x, id] = right.top();
        right.pop();
        left.push(id + A[id]);
      }
      while (!left.empty() && left.top() < i) {
        left.pop();
      }
      B[i] = left.size() + right.size();
    }
    while (!mi.empty()) {
      mi.pop();
    }
    while (!right.empty()) {
      right.pop();
    }
    while (!left.empty()) {
      left.pop();
    }
    A = B;
  }
  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;

#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (int(i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for (int(i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
// constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9 + 7;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  priority_queue<int, vector<int>, greater<int>> left;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      right, mi;
  REP(i, N) { cin >> A[i]; }

  int loop = min(100, K);
  while (loop--) {
    REP(i, N) { mi.push({i - A[i], i}); }
    vector<int> B(N);
    REP(i, N) {
      while (!mi.empty() && mi.top().first <= i) {
        auto [x, id] = mi.top();
        mi.pop();
        if (x <= i) {
          left.push(id + A[id]);
        } else {
          right.push({id - A[id], id});
        }
      }
      while (!right.empty() && right.top().first <= i) {
        auto [x, id] = right.top();
        right.pop();
        left.push(id + A[id]);
      }
      while (!left.empty() && left.top() < i) {
        left.pop();
      }
      B[i] = left.size() + right.size();
    }
    while (!mi.empty()) {
      mi.pop();
    }
    while (!right.empty()) {
      right.pop();
    }
    while (!left.empty()) {
      left.pop();
    }
    A = B;
  }
  REP(i, N) { cout << A[i] << " "; }
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

int main() {
  int n, t;
  cin >> n >> t;
  VI v(n), w(n);
  rep(i, n) cin >> v[i];
  rep(tt, t) {
    bool check = false;
    w = v;
    VI imos(n + 1, 0);
    rep(j, n) {
      imos[max(0, j - v[j])]++;
      imos[min(n, j + v[j] + 1)]--;
    }
    int cur = 0;
    rep(j, n) {
      cur += imos[j];
      v[j] = cur;
      check |= (v[j] != n);
    }
    if (check == false)
      break;
    cerr << v[0] << endl;
  }
  rep(i, v.size()) { cout << v[i] << " "; }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

int main() {
  int n, t;
  cin >> n >> t;
  VI v(n);
  rep(i, n) cin >> v[i];
  rep(i, t) {
    bool check = false;
    auto w = v;
    rep(j, v.size()) {
      int num = 0;

      rep(k, v.size()) {
        if (abs(j - k) <= w[k]) {
          num++;
        }
      }
      v[j] = num;
      check |= (num != n);
    }
    if (check == false)
      break;
  }
  rep(i, v.size()) { cout << v[i] << " "; }
  cout << endl;

  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 all(v) v.begin(), v.end()
//
vector<int> light(vector<int> v) {
  int N = v.size();
  vector<int> vv(N, 0);
  rep(i, v.size()) {
    int a, b;
    a = max(0, (i - v[i]));
    b = i + v[i] + 1;
    vv[a]++;
    if (b < N)
      vv[b]--;
  }
  rep(i, vv.size() - 1) { vv[i + 1] = min(vv[i + 1] + vv[i], N); }
  return vv;
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> v, check(N, N);
  if (K > 2 * N) {
    vector<int> vv(N, N);
    for (auto e : v)
      cout << e << " ";
    cout << endl;
    return 0;
  }
  rep(i, N) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  rep(i, K) {
    if (v == check)
      break;
    v = light(v);
  }
  for (auto e : v)
    cout << e << " ";
  cout << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
//
vector<int> light(vector<int> v) {
  int N = v.size();
  vector<int> vv(N, 0), check(N, N);
  rep(i, v.size()) {
    int a, b;
    a = max(0, (i - v[i]));
    b = i + v[i] + 1;
    vv[a]++;
    if (b < N)
      vv[b]--;
  }
  rep(i, vv.size() - 1) {
    vv[i + 1] = min(vv[i + 1] + vv[i], N);
    if (vv == check) {
      break;
    }
  }
  return vv;
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> v, check(N, N);
  if (K > 2 * N) {
    vector<int> vv(N, N);
    for (auto e : v)
      cout << e << " ";
    cout << endl;
    return 0;
  }
  rep(i, N) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  rep(i, K) {
    if (v == check)
      break;
    v = light(v);
  }
  for (auto e : v)
    cout << e << " ";
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) scanf("%lld", &a[i]);
  int cnt = 0;
  while (cnt < k) {
    vector<int> s(n + 1);
    rep(i, n) {
      int l = i - a[i];
      int r = i + a[i] + 1;
      if (l < 0)
        l = 0;
      if (r > n)
        r = n;
      s[l] += 1;
      s[r] += -1;
    }
    ll tmp = 0;
    bool flag = true;
    rep(i, n) {
      a[i] = tmp + s[i];
      if (a[i] != n)
        flag = false;
      tmp = a[i];
    }
    if (flag)
      break;
    cnt++;
  }
  rep(i, n) { printf("%lld ", a[i]); }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
  int n, k;
  cin >> n >> k;
  if (k >= n - 1) {
    rep(i, n) printf("%d ", n);
    cout << endl;
    return 0;
  }
  vector<ll> a(n);
  rep(i, n) scanf("%lld", &a[i]);
  int cnt = 0;
  while (cnt < k) {
    vector<int> s(n + 1);
    rep(i, n) {
      int l = i - a[i];
      int r = i + a[i] + 1;
      if (l < 0)
        l = 0;
      if (r > n)
        r = n;
      s[l] += 1;
      s[r] += -1;
    }
    ll tmp = 0;
    rep(i, n) {
      a[i] = tmp + s[i];
      tmp = a[i];
    }
    cnt++;
  }
  rep(i, n) { printf("%lld ", a[i]); }
  cout << endl;
  return 0;
}