alexjercan/bugnet huggingface dataset:
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 < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N + 1);
  rep(i, N) cin >> A[i];
  if (N <= K) {
    rep(i, N) {
      if (i)
        cout << " ";
      cout << N;
    }
    cout << endl;
    return 0;
  }
  rep(i, K) {
    vector<int> memo(N + 1);
    rep(i, N) {
      memo[max(i - A[i], 0)]++;
      memo[min(i + A[i] + 1, N)]--;
    }
    bool flag = true;
    rep(i, N) {
      memo[i + 1] = memo[i] + memo[i + 1];
      if (memo[i] != N)
        flag = false;
    }
    swap(memo, A);
    if (flag)
      break;
  }
  rep(i, N) {
    if (i)
      cout << " ";
    cout << A[i];
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N + 1);
  rep(i, N) cin >> A[i];
  if (N <= K) {
    rep(i, N) {
      if (i)
        cout << " ";
      cout << N;
    }
    cout << endl;
    return 0;
  }
  rep(i, K) {
    vector<int> memo(N + 1);
    rep(i, N) {
      memo[max(i - A[i], 0)]++;
      memo[min(i + A[i] + 1, N)]--;
    }
    rep(i, N) { memo[i + 1] = memo[i] + memo[i + 1]; }
    swap(memo, A);
  }
  rep(i, N) {
    if (i)
      cout << " ";
    cout << A[i];
  }
  cout << endl;
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template <class T> void chmin(T &x, T y) {
  if (x > y)
    x = y;
}
template <class T> void chmax(T &x, T y) {
  if (x < y)
    x = y;
}

int N, K;
int A[50][200010];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> K;

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

  K = min(K, 49);
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= N; j++) {
      A[i][max(1, j - A[i - 1][j])]++;
      A[i][min(j + A[i - 1][j] + 1, N + 1)]--;
    }

    for (int j = 1; j <= N; j++) {
      A[i][j + 1] += A[i][j];
    }
  }

  for (int i = 1; i <= N; i++) {
    cout << A[K][i];
    if (i != N)
      cout << " ";
    else
      cout << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template <class T> void chmin(T &x, T y) {
  if (x > y)
    x = y;
}
template <class T> void chmax(T &x, T y) {
  if (x < y)
    x = y;
}

int N, K;
int A[30][200010];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> K;
  for (int i = 1; i <= N; i++) {
    cin >> A[0][i];
  }
  K = min(K, 29);
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= N; j++) {
      A[i][max(0, j - A[i - 1][j])]++;
      A[i][min(j + A[i - 1][j] + 1, N + 1)]--;
    }

    for (int j = 1; j <= N; j++) {
      A[i][j + 1] += A[i][j];
    }
  }

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

#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(), x.end()
#define MOD (1000000000 + 7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x, y) make_pair(x, y)

int main() {
  ll N;
  ll K;
  cin >> N >> K;
  vector<ll> A(N);
  ll tp = 0;

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

  for (ll ii = 0; ii < K; ii++) {
    int tmp1[2002013] = {0};
    if (ii > 50) {

      tp = 1;
      break;
      ;
    }
    for (ll i = 0; i < N; i++) {
      ll lef = 0;
      if (i - A[i] > 0) {
        lef = i - A[i];
      }
      ll ri = i + A[i];
      tmp1[lef]++;
      tmp1[ri + 1]--;
    }
    ll rui = tmp1[0];
    for (ll i = 0; i < N; i++) {
      A[i] = rui;
      rui = tmp1[i + 1] + rui;
    }
  }
  if (tp == 1) {
    for (ll i = 0; i < N; i++) {
      cout << N << ' ';
    }
    return 0;
  }

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(), x.end()
#define MOD (1000000000 + 7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x, y) make_pair(x, y)

int main() {
  ll N;
  ll K;
  cin >> N >> K;
  vector<ll> A(N);

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

  for (ll ii = 0; ii < K; ii++) {
    int tmp1[2002013] = {0};
    for (ll i = 0; i < N; i++) {
      ll lef = 0;
      if (i - A[i] > 0) {
        lef = i - A[i];
      }
      ll ri = i + A[i];
      tmp1[lef]++;
      tmp1[ri + 1]--;
    }
    ll rui = tmp1[0];
    for (ll i = 0; i < N; i++) {
      A[i] = rui;
      rui = tmp1[i + 1] + rui;
    }
  }
  for (ll i = 0; i < N; i++) {
    cout << A[i] << ' ';
  }
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

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

vector<long long> solve(vector<long long> light) {
  long long n = light.size();
  vector<long long> table(n, 0);
  for (long long i = 0; i < n; i++) {
    long long start = max(0ll, i - light[i]);
    long long goal = min(n - 1, i + light[i]);
    table[start]++;
    if (goal + 1 < n)
      table[goal + 1]--;
  }

  for (long long i = 0; i < n; i++) {
    if (i > 0)
      table[i] += table[i - 1];
  }
  return table;
}
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> light(n);

  vector<long long> light_max(n, n);

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

  for (long long i = 0; i < k; i++) {
    light = solve(light);
    if (light == light_max) {
      for (long long j = 0; j < n; j++) {
        printf("%lld ", light_max[j]);
      }
      printf("\\n");
      return 0;
    }
  }

  for (long long i = 0; i < n; i++) {
    printf("%lld ", light[i]);
  }
  printf("\\n");
  return 0;
}

Error: WA

Fixed submission:

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

vector<long long> solve(vector<long long> light) {
  long long n = light.size();
  vector<long long> table(n + 1, 0);
  for (long long i = 0; i < n; i++) {
    long long start = max(0ll, i - light[i]);
    long long goal = min(n - 1, i + light[i]);
    table[start]++;
    table[goal + 1]--;
  }

  for (long long i = 0; i < n; i++) {
    if (i > 0)
      table[i] += table[i - 1];
  }
  return table;
}
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> light(n + 1);

  vector<long long> light_max(n + 1, n);

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

  for (long long i = 0; i < k; i++) {
    light = solve(light);
    if (light == light_max) {
      for (long long j = 0; j < n; j++) {
        printf("%lld ", light_max[j]);
      }
      printf("\\n");
      return 0;
    }
  }

  for (long long i = 0; i < n; i++) {
    printf("%lld ", light[i]);
  }
  printf("\\n");
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

ll N, K;
vector<ll> A;
vector<ll> B;

int main() {
  cin >> N >> K;
  A.resize(N);
  B.resize(N + 1);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll logN = log2(N) + 100;
  for (ll i = 0; i < min(K, logN); i++) {
    fill(B.begin(), B.end(), 0LL);
    for (ll j = 0; j < N; j++) {
      B[max(j - A[j], 0LL)]++;
      if (j + A[j] < N - 1)
        B[j + A[j] + 1]--;
    }
    for (ll j = 0; j < N; j++) {
      A[j] = B[j];
      B[j + 1] += B[j];
    }
  }
  for (ll i = 0; i < N; i++) {
    cout << B[i];
    if (i == N - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

ll N, K;
vector<ll> A;
vector<ll> B;

int main() {
  cin >> N >> K;
  A.resize(N);
  B.resize(N + 1);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll logN = log2(N) + 100000;
  for (ll i = 0; i < min(K, logN); i++) {
    fill(B.begin(), B.end(), 0LL);
    for (ll j = 0; j < N; j++) {
      B[max(j - A[j], 0LL)]++;
      if (j + A[j] < N - 1)
        B[j + A[j] + 1]--;
    }
    for (ll j = 0; j < N; j++) {
      A[j] = B[j];
      B[j + 1] += B[j];
    }
  }
  for (ll i = 0; i < N; i++) {
    cout << B[i];
    if (i == N - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
  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 < min(42, K); i++) {
    vector<int> B(N, 0);
    for (int j = 0; j < N; j++) {
      int l = max(0, j - A.at(j));
      int r = min(N - 1, j + A.at(j));
      B.at(l)++;
      if (r + 1 < N)
        B.at(r + 1)--;
    }
    for (int j = 1; j < N; j++) {
      B.at(j) += B.at(j - 1);
    }
    A = B;
  }

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

  cout << A.at(N - 1) << endl;
}

Error: TLE

Fixed submission:

#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 < min(42, K); i++) {
    vector<int> v(N, 0);
    for (int i = 0; i < N; i++) {
      for (int j = max(0, i - A.at(i)); j <= min(i + A.at(i), N - 1); j++) {
        v.at(j)++;
      }
    }
    A = v;
  }

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

  cout << A.at(N - 1) << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
// #define int ll

const int N = 2e5 + 10;
int a[N], b[N];

void add(int l, int r) {
  b[l]++;
  b[r + 1]--;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int iter = 1; iter <= k; iter++) {
    for (int i = 1; i <= n; i++) {
      a[i] = b[i];
      b[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
      add(max(1, i - a[i]), min(n, i + a[i]));
    }
    bool ok = true;
    for (int i = 1; i <= n; i++) {
      b[i] += b[i - 1];
      if (b[i] != n) {
        ok = false;
      }
    }
    if (ok) {
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << b[i] << ' ';
  }
  cout << '\\n';
}

Error: WA

Fixed submission:

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
// #define int ll

const int N = 1e5 + 10;
int a[N], b[N];

void add(int l, int r) {
  b[l]++;
  b[r + 1]--;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int iter = 1; iter <= k; iter++) {
    for (int i = 1; i <= n; i++) {
      a[i] = b[i];
      b[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
      add(max(1, i - a[i]), min(n, i + a[i]));
    }
    bool ok = true;
    for (int i = 1; i <= n; i++) {
      b[i] += b[i - 1];
      if (b[i] != n) {
        ok = false;
      }
    }
    if (ok) {
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << b[i] << ' ';
  }
  cout << '\\n';
}
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 repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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;
}

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll << 61;
double pi = 3.141592653589793238;

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

  rep(j, k) {
    rep(i, n + 1) table[i] = 0;

    rep(i, n) {
      table[max(0ll, i - a[i])]++;
      table[min(n, i + a[i] + 1)]--;
    }

    rep(i, n) {
      if (0 < i)
        table[i] += table[i - 1];
    }

    rep(i, n) a[i] = table[i];

    bool flag = true;
    rep(i, n) {
      if (a[i] != n) {
        flag = false;
        break;
      }
    }
    if (flag)
      break;
  }

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

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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;
}

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll << 61;
double pi = 3.141592653589793238;

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

  rep(j, k) {
    rep(i, n + 1) table[i] = 0;

    rep(i, n) {
      table[max(0ll, i - a[i])]++;
      table[min(n, i + a[i] + 1)]--;
    }

    rep(i, n) {
      if (0 < i)
        table[i] += table[i - 1];
    }

    rep(i, n) a[i] = table[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;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll << (x))
#define endl "\\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int a[200000 + 10];
int ma[200000 + 10];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  rep(i, 1, n + 1) { cin >> a[i]; }
  rep(j, 1, k + 1) {
    int flag = 0;
    rep(i, 1, n + 1) ma[i] = 0;
    rep(i, 1, n + 1) {
      if (i - a[i] <= 1)
        ma[1]++;
      else
        ma[i - a[i]]++;
      if (i + a[i] <= n)
        ma[i + a[i] + 1]--;
    }
    int sum = 0;
    rep(i, 1, n + 1) {
      sum += ma[i];
      a[i] = sum;
      if (sum != n)
        flag = 1;
    }
    if (flag == 0)
      break;
  }
  rep(i, 1, n + 1) cout << a[i] << " ";
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll << (x))
#define endl "\\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int a[200000 + 10];
map<int, int> ma;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  rep(i, 1, n + 1) { cin >> a[i]; }
  rep(j, 1, k + 1) {
    int flag = 0;
    ma.clear();
    rep(i, 1, n + 1) {
      if (i - a[i] <= 1)
        ma[1]++;
      else
        ma[i - a[i]]++;
      if (i + a[i] <= n)
        ma[i + a[i] + 1]--;
    }
    int sum = 0;
    rep(i, 1, n + 1) {
      sum += ma[i];
      a[i] = sum;
      if (sum != n)
        flag = 1;
    }
    if (flag == 0)
      break;
  }
  rep(i, 1, n + 1) cout << a[i] << " ";
  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 n = 0; n < N; ++n) {
    cin >> A[n];
  }
  for (int n = 0; n < K; ++n) {
    bool end = true;
    vector<int> B(N);
    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];
      if (N != B[i]) {
        end = false;
      }
    }
    A = B;
    if (end) {
      break;
    }
  }

  for (int n = 0; n < N; ++n) {
    cout << A[n];
    if (n != N - 1) {
      cout << " ";
    }
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N); // 初期パワー
  for (int n = 0; n < N; ++n) {
    cin >> A[n];
  }
  // bool end = true;
  for (int n = 0; n < K; ++n) {
    vector<int> B(N);
    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];
      /*if (N != B[i]) {
              end = false;
      }*/
    }
    A = B;
    /*if (end) {
            break;
    }*/
  }

  for (int n = 0; n < N; ++n) {
    cout << A[n];
    if (n != N - 1) {
      cout << " ";
    }
  }
  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++)   // 普通のループ
#define REPR(i, n) for (int i = n; i >= 0; i--) // 逆ループ
#define FOR(i, m, n) for (int i = m; i < n; i++) // 最初の数値を指定したループ

// 型名省略
typedef long long ll;
// 配列要素数
static const int MAX = 200000;
// 値
static const ll MX = 1e18;

using namespace std;

// #include "./lib/generic/search.h"

#define M 1064527

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  REP(i, N) cin >> a[i];
  REP(j, K) {
    vector<int> b(N + 1);
    REP(i, N) {
      int l = max(0, i - a[i]);
      int r = min(N, i + a[i] + 1);
      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: TLE

Fixed submission:

#include <bits/stdc++.h> //全てのヘッダファイルをインクルード

// ループ
#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, m, n) for (int i = m; i < n; i++) // 最初の数値を指定したループ

// 型名省略
typedef long long ll;
// 配列要素数
static const int MAX = 200000;
// 値
static const ll MX = 1e18;

using namespace std;

// #include "./lib/generic/search.h"

#define M 1064527

int main() {
  int N, K;
  cin >> N >> K;
  int A[N], B[N + 1];
  REP(i, N) {
    cin >> A[i];
    B[i] = 0;
  }
  B[N] = 0;

  int D1, D2, o = 1, sum = 0;
  REP(i, K) {
    sum = 0;
    REP(j, N) {
      D1 = max(0, j - A[j]);
      B[D1]++;
      D2 = min(N, j + A[j] + 1);
      B[D2]--;
    }

    REP(i, N) {
      B[i + 1] += B[i];
      A[i] = B[i];
      B[i] = 0;
    }

    REP(i, N) {
      if (A[i] == B[i])
        sum++;
    }
    if (sum == N)
      break;
  }

  REP(i, N) {
    if (i != 0) {
      cout << " ";
    }
    cout << A[i];
  }

  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);
  vector<int> B(N, 0);

  int count = 0;
  // int all;
  while (count < K) {
    // all=0;
    for (int i = 0; i < N; i++) {
      int l = max(0, i - A[i]);
      int r = min(N - 1, i + A[i]);
      B.at(l)++;
      if (r + 1 < N)
        B.at(r + 1)--;
    }
    for (int i = 1; i < N; i++)
      B.at(i) += B.at(i - 1);

    for (int i = 0; i < N; i++) {
      A.at(i) = B.at(i);
      B.at(i) = 0;
    }
    bool can = false;
    for (int j = 0; j < N; j++) {
      if (A.at(j) != N)
        can = true;
      // goto Fin;
    }
    if (!can)
      break;
    count++;
  }
  // Fin:
  for (int i = 0; i < N; i++)
    cout << A.at(i) << " ";
}


Error: TLE

Fixed submission:

#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);
  vector<int> B(N);

  int count = 0;
  int all;
  for (int i = 0; i < N; i++)
    B.at(i) = 0;
  while (count < K) {
    all = 0;
    for (int i = 0; i < N; i++) {
      int d = A.at(i);
      int left = max((i + 1) - d, 1);
      int right = min((i + 1) + d, N);
      if (left == 1 && right == N)
        all++;
      else
        for (int j = left - 1; j < right; j++)
          B.at(j)++;
    }
    for (int i = 0; i < N; i++) {
      A.at(i) = B.at(i) + all;
      B.at(i) = 0;
    }
    count++;
  }
  for (int i = 0; i < N; i++)
    cout << A.at(i) << " ";
}