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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define Check system("pause")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

int a[200005], b[200005];

int main() {
  ios::sync_with_stdio(false);
  int n, k, w, t;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  while (k--) {
    for (int i = 1; i <= n; i++) {
      b[max(1, i - a[i])] += 1;
      b[min(n + 1, i + a[i] + 1)] -= 1;
    }
    w = t = 0;
    for (int i = 1; i <= n; i++) {
      w += b[i];
      a[i] = w;
      b[i] = 0;
      if (a[i] != n)
        t = 1;
    }
    if (!t)
      break;
  }
  for (int i = 1; i <= n; i++)
    cout << a[i] << ' ';
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define Check system("pause")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

int a[200005], b[200005];

int main() {
  ios::sync_with_stdio(false);
  int n, k, w;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  while (k--) {
    for (int i = 1; i <= n; i++) {
      b[max(1, i - a[i])] += 1;
      b[min(n + 1, i + a[i] + 1)] -= 1;
    }
    w = 0;
    for (int i = 1; i <= n; i++) {
      w += b[i];
      a[i] = w;
      b[i] = 0;
    }
  }
  for (int i = 1; i <= n; i++)
    cout << a[i] << ' ';
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int, int> P;

const int MOD = 1000000007;
int INF = 100100100100100;
int a[200010];
int imos[200010];
signed main() {
  int n, k;
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  rep(ima, k) {
    rep(i, n) {
      if (i - a[i] >= 0)
        imos[i - a[i]]++;
      else
        imos[0]++;
      if (i + a[i] <= n - 1)
        imos[i + a[i] + 1]--;
      else
        imos[n]--;
    }
    int cnt = 0;
    rep(i, n) {
      if (i == 0)
        a[0] = imos[0];
      else
        a[i] = a[i - 1] + imos[i];
      if (a[i] == n)
        cnt++;
      imos[i] = 0;
    }
    if (cnt == n) {
      break;
    }
  }
  rep(i, n) cout << a[i] << " ";
  cout << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int, int> P;

const int MOD = 1000000007;
int INF = 100100100100100;
int a[100010];
int imos[100010];
signed main() {
  int n, k;
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  rep(ima, k) {
    rep(i, n) {
      if (i - a[i] >= 0)
        imos[i - a[i]]++;
      else
        imos[0]++;
      if (i + a[i] <= n - 1)
        imos[i + a[i] + 1]--;
      else
        imos[n]--;
    }
    int cnt = 0;
    rep(i, n) {
      if (i == 0)
        a[0] = imos[0];
      else
        a[i] = a[i - 1] + imos[i];
      if (a[i] == n)
        cnt++;
      imos[i] = 0;
    }
    if (cnt == n) {
      break;
    }
  }
  rep(i, n) cout << a[i] << " ";
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("Ofast")
#include <algorithm>
#include <stdio.h>
using namespace std;
int num[200005], num2[200005];
int main() {
  int i, j, l, n, k;
  scanf("%d%d", &n, &k);
  for (i = 0; i < n; i++)
    scanf("%d", &num[i]);
  for (i = 0; i < k; i++) {
    for (j = 0; j < n; j++)
      num2[j] = 0;
    for (j = 0; j < n; j++) {
      num2[max(0, -num[j] + j)]++;
      num2[min(n, num[j] + j) + 1]--;
    }
    for (j = 1; j < n; j++) {
      num2[j] += num2[j - 1];
    }
    bool right = 1;
    for (j = 0; j < n; j++) {
      num[j] = num2[j];
      right &= (num[j] == n);
    }
    if (right)
      break;
    //	for(j=0;j<n;j++)
    //		printf("%d ",num[j]);
    //	putchar('\\n');
  }
  for (i = 0; i < n; i++)
    printf("%d ", num[i]);
}


Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast")
#include <algorithm>
#include <stdio.h>
using namespace std;
int num[200005], num2[200005];
int main() {
  int i, j, l, n, k;
  scanf("%d%d", &n, &k);
  for (i = 0; i < n; i++)
    scanf("%d", &num[i]);
  for (i = 0; i < k; i++) {
    for (j = 0; j < n; j++)
      num2[j] = 0;
    for (j = 0; j < n; j++)
      for (l = max(0, -num[j] + j); l <= min(n, num[j] + j); l++)
        num2[l]++;
    bool right = 1;
    for (j = 0; j < n; j++) {
      num[j] = num2[j];
      right &= (num[j] == n);
    }
    if (right)
      break;
  }
  for (i = 0; i < n; i++)
    printf("%d ", num[i]);
}
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[i];

  if (k >= n - 1) { // TLE対策1
    for (int i = 1; i <= n; i++)
      cout << n << " ";
    cout << endl;
    return 0;
  }

  // 回答を観た（imos法：累積和による実装により、メインの計算量をO(n)にできる！）
  for (int j = 0; j < k; j++) {
    vector<int> b(n + 1);

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

    a = b;
  }

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

Error: TLE

Fixed submission:

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

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

  if (k >= n - 1) { // TLE対策1
    for (int i = 1; i <= n; i++)
      cout << n << " ";
    cout << endl;
    return 0;
  }

  for (int j = 0; j < k; j++) {
    vector<long long> b(n + 1, 0);

    for (int i = 1; i <= n; i++) {
      for (int k = -a[i] - 0.5; k < a[i] + 0.5; k++) {
        if (i + k > 0 && i + k <= n)
          b[i + k]++;
      }
    }

    a = b;
  }

  for (int i = 1; i <= n; i++)
    cout << a[i] << " ";
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;

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

  vector<int> av;
  vector<int> bv;
  av.reserve(n);
  bv.reserve(n);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    av.push_back(a);
    bv.push_back(0);
  }

  for (int r = 0; r < k; ++r) {
    for (int i = 0; i < n; ++i) {
      int l = std::max(i - av[i], 0);
      int r = i + av[i] + 1;
      ++bv[l];
      if (r < n)
        --bv[r];
    }

    for (int i = 1; i < n; ++i) {
      bv[i] += bv[i - 1];
    }

    bool end = true;
    for (int i = 0; i < n; ++i) {
      if (av[i] != bv[i])
        end = false;
      av[i] = bv[i];
      bv[i] = 0;
    }
    if (end)
      break;
  }

  for (int i = 0; i < n - 1; ++i)
    cout << av[i] << " ";
  cout << av[n - 1] << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

struct Light {
  int a = 0;
  int b = 0;
  bool isMax;
};

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

  vector<Light> av;
  av.reserve(n);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    bool isMax = i + a >= n - 1 && i - a <= 0;
    av.push_back(Light{a, 0, isMax});
  }

  if (n <= k) {
    for (int i = 0; i < n; ++i) {
      cout << n;
      if (i < n - 1)
        cout << " ";
      else
        cout << endl;
    }
    return 0;
  }

  for (int r = 0; r < k; ++r) {
    int maxCount = 0;
    for (int i = 0; i < n; ++i) {
      if (av[i].isMax) {
        ++maxCount;
        continue;
      }
      int left = std::max(i - av[i].a, 0);
      int right = std::min(i + av[i].a, n - 1);
      for (int j = left; j <= right; ++j) {
        ++av[j].b;
      }
    }
    for (int i = 0; i < n; ++i) {
      int a = av[i].b + maxCount;
      bool isMax = i + a >= n - 1 && i - a <= 0;
      av[i].a = a;
      av[i].b = 0;
      av[i].isMax = isMax;
    }
  }

  for (int i = 0; i < n; ++i) {
    cout << av[i].a;
    if (i < n - 1)
      cout << " ";
    else
      cout << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i, a, b) for (int i = a; i < b; ++i)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  vector<int> additions(N + 1, 0);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  while (K--) {
    queue<pair<pair<int, int>, long long>> Q;
    for (int i = 0; i < N; ++i) {
      long long val = A[i];
      if (val) {
        additions[max(i - val, 0ll)] += 1;
        additions[i] -= 1;
        additions[i + 1] += 1;
        additions[min((ll)N, i + val + 1)] -= 1;
      }
      additions[i] += (1 - val);
      additions[i + 1] -= (1 - val);
    }
    bool finished = true;
    A[0] = A[0] + additions[0];
    for (int i = 1; i < N; ++i) {
      additions[i] += additions[i - 1];
      A[i] = A[i] + additions[i];
    }
    additions.assign(N + 1, 0);

    for (int i = 0; i < N; ++i) {
      if (A[i] != N) {
        finished = false;
        break;
      }
    }
    if (finished)
      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;
#define ll long long
#define loop(i, a, b) for (int i = a; i < b; ++i)

struct rangeAddPointQuery {
  int size;
  vector<long long> array;
  void build(int n) {
    size = 1;
    while (size < n)
      size *= 2;
    array.assign(2 * size, 0);
  }

  void addrec(int l, int r, long long v, int x, int lx, int rx) {
    if (lx >= r || rx <= l)
      return;
    if (lx >= l && rx <= r) {
      array[x] += v;
      return;
    }
    int mid = (lx + rx) / 2;
    addrec(l, r, v, 2 * x + 1, lx, mid);
    addrec(l, r, v, 2 * x + 2, mid, rx);
  }

  void add(int l, int r, long long v) { addrec(l, r, v, 0, 0, size); }

  long long getrec(int index, int x, int lx, int rx) {
    if (rx - lx == 1)
      return array[x];
    int mid = (lx + rx) / 2;
    if (mid > index)
      return (array[x] + getrec(index, 2 * x + 1, lx, mid));
    return (array[x] + getrec(index, 2 * x + 2, mid, rx));
  }
  long long get(int index) { return getrec(index, 0, 0, size); }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  rangeAddPointQuery S;
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  S.build(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    S.add(i, i + 1, A[i]);
  }
  while (K--) {
    queue<pair<pair<int, int>, long long>> Q;
    for (int i = 0; i < N; ++i) {
      long long val = S.get(i);
      if (val) {
        Q.push({{max(i - val, 0ll), i}, 1});
        Q.push({{i + 1, min((ll)N, i + val + 1)}, 1});
      }
      Q.push({{i, i + 1}, 1 - val});
    }
    while (!Q.empty()) {
      S.add(Q.front().first.first, Q.front().first.second, Q.front().second);
      Q.pop();
    }
    bool finished = true;
    for (int i = 0; i < N; ++i) {
      if (S.get(i) != N) {
        finished = false;
        break;
      }
    }
    if (finished)
      break;
  }
  for (int i = 0; i < N; ++i)
    cout << S.get(i) << " ";
  cout << "\\n";
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using ll = long long;
#define fast_io()                                                              \\
  ;                                                                            \\
  std::ios_base::sync_with_stdio(0);                                           \\
  std::cin.tie(0);                                                             \\
  std::cout.tie(0);

int main() {
  fast_io();

  int N, K;
  std::cin >> N >> K;
  std::vector<int> A;
  for (int i = 0; i < N; i++) {
    int b;
    std::cin >> b;
    A.push_back(b);
  }

  for (int k = 0; k < K; k++) {
    std::vector<int> B(N, 0);
    for (int i = 0; i < N; i++) {
      int l = std::max(0, i - A[i]), r = std::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];
    if (A == B) {
      break;
    } else {
      A = B;
    }
  }

  for (int i = 0; i < N; i++) {
    std::cout << A[i] << " ";
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using ll = long long;

int main() {
  int N, K;
  std::cin >> N >> K;
  std::vector<int> A;
  for (int i = 0; i < N; i++) {
    int b;
    std::cin >> b;
    A.push_back(b);
  }

  for (int k = 0; k < K; k++) {
    std::vector<int> B(N, 0);
    for (int i = 0; i < N; i++) {
      for (int j = -A[i]; j <= A[i]; j++) {
        if (i + j >= 0 && i + j < N)
          B[i + j] += 1;
      }
    }
    if (A == B) {
      for (int i = 0; i < N; i++) {
        std::cout << A[i] << " ";
      }
      return 0;
    } else {
      A = B;
    }
  }

  for (int i = 0; i < N; i++) {
    std::cout << A[i] << " ";
  }
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;

const int MAX = 1e5 + 5;

int 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> b(n);
    for (int j = 0; j < n; j++) {
      int l = max(0, j - a[j]);
      int r = min(n - 1, j + a[j]);
      b[l]++;
      if (r + 1 < n) {
        b[r + 1]--;
      }
    }
    for (int j = 1; j < n; j++) {
      b[j] += b[j - 1];
    }

    bool isEnd = true;
    for (int j = 0; j < n; j++) {
      if (a[j] != n) {
        isEnd = false;
        break;
      }
    }

    if (isEnd) {
      for (int j = 0; j < n; j++) {
        cout << n << " ";
      }
      cout << endl;
      return 0;
    }
    a = b;
  }

  for (int ai : a) {
    cout << ai << " ";
  }

  cout << endl;
}

Error: WA

Fixed submission:

#define _USE_MATH_DEFINES

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;

const int MAX = 1e5 + 5;

int 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> b(n);
    for (int j = 0; j < n; j++) {
      int l = max(0, j - a[j]);
      int r = min(n - 1, i + a[i]);
      b[l]++;
      if (r + 1 < n) {
        b[r + 1]--;
      }
    }
    for (int j = 1; j < n; j++) {
      b[j] += b[j - 1];
    }

    bool isEnd = true;
    for (int j = 0; j < n; j++) {
      if (a[j] != n) {
        isEnd = false;
        break;
      }
    }

    if (isEnd) {
      for (int j = 0; j < n; j++) {
        cout << n << " ";
      }
      cout << endl;
      return 0;
    }
    a = b;
  }

  for (int ai : a) {
    cout << ai << " ";
  }

  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
typedef long long int ll;
const int N = 2e5 + 10;
int lazy[4 * N];
int a[N];
vector<int> b(N + 1);
int get(int idx, int l, int r, int id) {
  if (l == r) {
    b[l] += lazy[idx];
    lazy[idx] = 0;
    return b[l];
  }
  int mid = (l + r) / 2;
  lazy[2 * idx] += lazy[idx];
  lazy[2 * idx + 1] += lazy[idx];
  lazy[idx] = 0;
  if (id > mid) {
    return get(2 * idx + 1, mid + 1, r, id);
  } else {
    return get(2 * idx, l, mid, id);
  }
}
void update(int idx, int l, int r, int x, int y, int add) {
  if (l >= x && r <= y) {
    lazy[idx] += add;
    return;
  }
  if (x > r || y < l) {
    return;
  }
  int mid = (l + r) / 2;
  update(2 * idx, l, mid, x, y, add);
  update(2 * idx + 1, mid + 1, r, x, y, add);
}
int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int k;
  cin >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int d = 1; d <= k; d++) {
    b.clear();
    b.resize(n + 1);
    memset(lazy, 0, sizeof lazy);
    for (int i = 1; i <= n; i++) {
      int lol = a[i];
      update(1, 1, n, max(i - lol, 1), min(i + lol, n), 1);
    }
    for (int i = 1; i <= n; i++) {
      a[i] = get(1, 1, n, i);
      // cout<<a[i]<<" ";
    }

    // cout<<endl;
    bool cycle = true;
    for (int j = 1; j <= n; j++) {
      if (a[j] != n) {
        cycle = false;
        break;
      }
    }
    if (cycle) {
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
typedef long long int ll;
const int N = 2e5 + 10;
int a[N];
int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int k;
  cin >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int d = 1; d <= k; d++) {
    vector<int> b(n + 1, 0);
    for (int i = 1; i <= n; i++) {
      // cout<<"case "<<i<<endl;
      for (int j = max(i - a[i], 1); j <= min(i + a[i], n); j++) {
        // cout<<j<<endl;
        b[j]++;
      }
    }
    for (int i = 1; i <= n; i++) {
      a[i] = b[i];
    }
    /*
            for(int i=1; i<=n; i++) {
                    cout<<a[i]<<" ";
            }
     */
    // cout<<endl;
    bool cycle = true;
    for (int j = 1; j <= n; j++) {
      if (a[j] != n) {
        cycle = false;
        break;
      }
    }
    if (cycle) {
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;

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

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

int main() {
  int N, K;
  cin >> N;
  cin >> K;
  vector<int> A(N);
  vector<int> flash;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  rep(iterate, K) {
    flash = vector<int>(N, 0);
    rep(i, N) {
      int on = i - A[i];
      int off = i + A[i] + 1;
      if (on < 0) {
        flash[0] += 1;
      } else {
        flash[on] += 1;
      }
      if (off < N) {
        flash[off] -= 1;
      }
    }
    A[0] = flash[0];
    rep(i, N - 1) {
      A[i + 1] = A[i];
      A[i + 1] += flash[i + 1];
    }
    if (accumulate(A.begin(), A.end(), 0) == N * N) {
      break;
    }
  }

  for (int i = 0; i < N - 1; i++) {
    cout << A.at(i) << " ";
  }
  cout << A.at(A.size() - 1) << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, K;
  cin >> N;
  cin >> K;
  vector<int> A(N);
  vector<int> flash;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  rep(iterate, K) {
    flash = vector<int>(N, 0);
    rep(i, N) {
      int on = i - A[i];
      int off = i + A[i] + 1;
      if (on < 0) {
        flash[0] += 1;
      } else {
        flash[on] += 1;
      }
      if (off < N) {
        flash[off] -= 1;
      }
    }
    A[0] = flash[0];
    rep(i, N - 1) {
      A[i + 1] = A[i];
      A[i + 1] += flash[i + 1];
    }
  }

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

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

lint gcd(lint x, lint y) {
  if (x == 0) {
    return y;
  } else {
    return gcd(y % x, x);
  }
}

lint lcm(lint x, lint y) { return x / gcd(x, y) * y; }

lint C(lint n, lint k) {
  if (n == k) {
    return 1;
  } else if (n < k) {
    return 0;
  } else if (k == 0) {
    return 1;
  } else if (k == 1) {
    return n;
  } else
    return C(n - 1, k - 1) + C(n - 1, k);
}

lint P(lint n, lint k) {
  if (k == 1) {
    return n;
  }
  return (n * (P(n - 1, k - 1) % 1000000007) % 1000000007);
}

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

  for (int i = 0; i < k; i++) {
    vector<lint> c(n + 1, 0);
    for (int j = 0; j < n; j++) {
      c[max(0LL, j - a[j])]++;
      c[min(j + a[j] + 1, n)]--;
    }

    a[0] = c[0];
    for (int j = 1; j < n; j++) {
      a[j] = c[j] + a[j - 1];
    }

    int check = 1;
    for (int j = 0; j < n; j++) {
      if (a[j] != n) {
        check *= 0;
      }
    }
    if (check == 1) {
      break;
    }
  }

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


Error: TLE

Fixed submission:

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

lint gcd(lint x, lint y) {
  if (x == 0) {
    return y;
  } else {
    return gcd(y % x, x);
  }
}

lint lcm(lint x, lint y) { return x / gcd(x, y) * y; }

lint C(lint n, lint k) {
  if (n == k) {
    return 1;
  } else if (n < k) {
    return 0;
  } else if (k == 0) {
    return 1;
  } else if (k == 1) {
    return n;
  } else
    return C(n - 1, k - 1) + C(n - 1, k);
}

lint P(lint n, lint k) {
  if (k == 1) {
    return n;
  }
  return (n * (P(n - 1, k - 1) % 1000000007) % 1000000007);
}

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

  for (int i = 0; i < k; i++) {
    vector<lint> c(n + 1, 0);
    for (int j = 0; j < n; j++) {
      c[max(0LL, j - a[j])]++;
      c[min(j + a[j] + 1, n)]--;
    }

    a[0] = c[0];
    for (int j = 1; j < n; j++) {
      a[j] = c[j] + a[j - 1];
    }
  }

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