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

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> prev(n);
  for (int i = 0; i < n; i++) {
    cin >> prev[i];
  }
  vector<int> act(n, n);
  for (int i = 0; i < k && prev != act; i++) {
    vector<int> next(n + 1, 0);
    for (int j = 0; j < n; j++) {
      int k = max(0, j - prev[j]);
      int l = min(n, j + prev[j] + 1);
      next[k]++;
      next[l]--;
      // cout<<k<<" "<<l<<endl;
    }
    for (int j = 0; j < n; j++) {
      next[j + 1] += next[j];
      // cout<<next[j]<<" ";
    }
    next.pop_back();
    // cout<<endl;
    prev = next;
  }
  for (int i = 0; i < n; i++)
    cout << prev[i] << " ";
}


Error: TLE

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> prev(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> prev[i];
  }
  vector<int> next(n + 1, 0);
  vector<int> act(n + 1, n);
  act[0] = 0;
  for (int i = 0; i < k && prev != act; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = max(1, j - prev[j]); k <= min(n, j + prev[j]); k++) {
        next[k]++;
      }
    }
    prev = next;
    next = vector<int>(n + 1, 0);
  }
  for (int i = 1; i <= n; i++)
    cout << prev[i] << " ";
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define N 200010
// #define M 61
// #define MOD 100003
// vector <pair<int,int> > edge[M];
// int d[N][N];
// priority_queue <pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >q;
// queue <int> q;
// ll cnte[N];
// int ans=0;
// vector <int> edge[N];
int a[N];
int b[N];
int n, k;

void func(int a[], int b[]) {
  for (int i = 1; i <= n; i++)
    a[i] = b[i] + a[i - 1];
}

bool judge(int a[]) {
  for (int i = 1; i <= n; i++)
    if (a[i] != n)
      return false;
  return true;
}
/*
void outb(int b[])
{
        cout<<"b: ";
//	cout<<"n:"<<n<<endl;
        for (int i=1;i<=n;i++)
                cout<<b[i]<<" ";
        cout<<endl;
}
*/
/*
void outa(int a[])
{
        cout<<"a: ";
        for (int i=1;i<=n;i++)
                cout<<a[i]<<" ";
        cout<<endl;
}
*/

void solve() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= k; i++) {
    memset(b, 0, sizeof(b));
    for (int j = 1; j <= n; j++) {
      int l = max(1, j - a[j]);
      int r = min(n, j + a[j]);
      b[l]++;
      b[r + 1]--;
      //	outb(b);
      //	outa(a);
    }
    func(a, b);
    if (judge(a))
      break;
  }
  for (int i = 1; i <= n; i++)
    cout << a[i] << " ";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //	int t;
  //	cin>>t;
  //	while (t--)
  solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define N 200010
// #define M 61
// #define MOD 100003
// vector <pair<int,int> > edge[M];
// int d[N][N];
// priority_queue <pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >q;
// queue <int> q;
// ll cnte[N];
// int ans=0;
// vector <int> edge[N];
int a[N];
int b[N];
int n, k;
void copy(int a[], int b[]) {
  for (int i = 1; i <= n; i++)
    b[i] = a[i];
}

void solve() {

  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];

  copy(a, b);
  for (int i = 1; i <= k; i++) {
    copy(b, a);
    bool flag = true;
    memset(b, 0, sizeof(b));
    for (int j = 1; j <= n; j++) {
      //	cout<<"l:"<<max(1,j-a[j])<<" "<<"r: "<<min(n,j+a[j])<<endl;
      for (int l = max(1, j - a[j]); l <= min(n, j + a[j]); l++) {
        b[l]++;
        //		cout<<"no:"<<l<<"   "<<"b[no]"<<b[l]<<endl;
      }
    }
    for (int j = 1; j <= n; j++)
      if (b[j] != n) {
        flag = false;
        break;
      }
    if (flag)
      break;
  }
  //	copy(b,a);
  for (int i = 1; i <= n; i++)
    cout << b[i] << " ";
  cout << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //	int t;
  //	cin>>t;
  //	while (t--)
  solve();
  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 long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll> P;
typedef tuple<ll, int, int> T;
#define PI 3.14159265358979

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) { cin >> A[i]; }

  rep(i, K) {
    vector<ll> B(N, 0ll);
    rep(j, N) {
      ll l = max(0ll, j - A[j]);
      ll r = min(N - 1ll, j + A[j]);
      B[l]++;
      if (r + 1 < N)
        B[r + 1]--;
    }
    for (ll j = 1; j < N; j++) {
      B[j] += B[j - 1];
    }
    int flag = 0;
    rep(j, N) {
      A[j] = B[j];
      if (A[j] != N) {
        flag = 1;
      }
    }
    if (flag == 0) {
      break;
    }
  }
  rep(i, N) { cout << A[i] << ' '; }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<ll, ll> P;
typedef tuple<ll, int, int, int, int, int, int, int> T;
#define PI 3.14159265358979
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 100000000;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) { cin >> A[i]; }

  rep(i, K) {
    vector<ll> memo(N + 1);
    rep(j, N) { memo[j] = 0; }
    rep(j, N) {
      ll p = A[j];
      if (j - p < 0) {
        memo[0]++;
      } else {
        memo[j + 1 - p]++;
      }
      if (j + p + 1 > N) {
      } else {
        memo[j + p + 2]--;
      }
    }
    ll sum = 0;
    sum += memo[0];
    rep(j, N) {
      sum += memo[j + 1];
      A[j] = sum;
    }
    int flag = 0;
    rep(j, N) {
      if (A[i] != N) {
        flag = 1;
      }
    }
    if (flag == 0) {
      break;
    }
  }
  rep(i, N) { cout << A[i] << ' '; }
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 9;
int A[maxn];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    scanf("%d", &A[i]);
  while (k--) {
    int B[maxn];
    memset(B, 0, sizeof(B));
    for (int i = 1; i <= n; i++) {
      int l = max(1, i - A[i]);
      int r = min(n, i + A[i]);
      // 差分
      B[l]++;
      B[r + 1]--;
    }
    // 差分应用
    for (int i = 1; i <= n; i++) {
      A[i] = A[i - 1] + B[i];
    }
    if (A[n] == n)
      break;
  }
  for (int i = 1; i <= n; i++) {
    printf("%d ", A[i]);
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
const int maxn = 2e5 + 10;
int A[maxn];
int main() {
  int N, K;
  cin >> N >> K;
  for (int i = 1; i <= N; i++)
    cin >> A[i];
  int k = 1;
  while (k <= K) {
    int B[maxn];
    memset(B, 0, sizeof(B));
    for (int i = 1; i <= N; i++) {
      for (int j = i; j <= i + A[i]; j++) {
        B[j]++;
      }
      for (int j = i - 1; j >= 1; j--) {
        if (j < i - A[i])
          break;
        B[j]++;
      }
    }
    for (int i = 1; i <= N; i++) {
      A[i] = B[i];
      // printf("%d ",A[i]);
    }
    // printf("\\n");
    if (k == N)
      break;
    k++;
  }
  for (int i = 1; i <= N; i++) {
    printf("%d ", A[i]);
  }
  printf("\\n");
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
  int N, K;
  cin >> N >> K;
  vi A(N);
  REP(i, 0, N) cin >> A[i];
  REP(i, 0, K) {
    vi cum(N, 0);
    REP(j, 0, N) {
      int l = max(0, j - A[j]);
      int r = min(j + A[j], N - 1);
      cum[l]++;
      if (r + 1 < N)
        cum[r + 1]--;
    }
    REP(i, 1, N) cum[i] += cum[i - 1];
    REP(i, 0, N) A[i] = cum[i];
    if (i >= 64)
      break;
  }
  REP(i, 0, N) cout << A[i] << " ";
  cout << endl;
}

Error: TLE

Fixed submission:

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
  int N, K;
  cin >> N >> K;
  vi A(N);
  REP(i, 0, N) cin >> A[i];
  REP(i, 0, K) {
    vi newA(N, 0);
    REP(j, 0, N) {
      REP(k, 0, N) {
        if (A[k] - abs(j - k) >= 0)
          newA[j]++;
      }
    }
    REP(i, 0, N) A[i] = newA[i];
  }
  REP(i, 0, N) cout << A[i] << " ";
  cout << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/13/20 21:03:09
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<int> A(n);
  for (auto &a : A)
    cin >> a;
  vector<int> ans(n);
  while (k--) {
    ans.assign(n, 0);
    for (int i = 0; i < n; i++) {
      ans[max(0, i - A[i])]++;
      if (i + A[i] + 1 < n)
        ans[i + A[i] + 1]--;
    }
    for (int i = 1; i < n; i++)
      ans[i] += ans[i - 1];
    bool skip = true;
    for (int i = 0; i < n; i++) {
      if (ans[i] < n) {
        skip = false;
        break;
      }
    }
    if (skip)
      break;
    A = ans;
  }
  for (auto a : ans)
    cout << a << " ";
  cout << endl;

  return 0;
}


Error: TLE

Fixed submission:

// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/13/20 21:03:09
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<int> A(n);
  for (auto &a : A)
    cin >> a;
  vector<int> ans(n);
  while (k--) {
    ans.assign(n, 0);
    for (int i = 0; i < n; i++) {
      ans[max(0, i - A[i])]++;
      if (i + A[i] + 1 < n)
        ans[i + A[i] + 1]--;
    }
    for (int i = 1; i < n; i++)
      ans[i] += ans[i - 1];
    bool skip;
    for (int i = 0; i < n; i++) {
      if (ans[i] != A[i]) {
        skip = false;
        break;
      }
    }
    if (skip)
      break;
    A = ans;
  }
  for (auto a : ans)
    cout << a << " ";
  cout << endl;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
int a[212345];
int b[212345];
int kuai[212345];
void print(int n) {
  for (int i = 1; i <= n; ++i)
    cout << a[i] << " ";
  cout << endl;
}
signed main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  int n, k, i, j, t, left, right;
  t = 0;
  cin >> n >> k;
  int N = int(sqrt(n));
  for (i = 1; i <= n; ++i)
    cin >> a[i];
  while (k--) {
    t = 0;
    for (i = 1; i <= n; ++i) {
      left = max(1, i - a[i]);
      right = min(n, i + a[i]);
      if (left == 1 && right == n)
        ++t;
      else {
        if (right / N - left / N <= 1) {
          for (j = left; j <= right; ++j)
            ++b[j];
        } else {
          for (j = left / N + 1; j < right / N; ++j) {
            ++kuai[j];
          }
          for (j = left; j < (left / N + 1) * N; ++j)
            ++b[j];
          for (j = (right / N) * N; j <= right; ++j)
            ++b[j];
        }
      }
    }
    for (i = 1; i <= n; ++i) {
      a[i] = b[i] + t + kuai[i / N];
      b[i] = 0;
    }
    for (i = 0; i < N + 5; ++i)
      kuai[i] = 0;
    if (t == n)
      break;
  }
  print(n);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
int a[212345];
int b[212345];
void print(int n) {
  for (int i = 1; i <= n; ++i)
    cout << a[i] << " ";
  cout << endl;
}
signed main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  int n, k, i, j, t, left, right;
  t = 0;
  cin >> n >> k;
  for (i = 1; i <= n; ++i)
    cin >> a[i];
  while (k--) {
    t = 0;
    for (i = 1; i <= n; ++i) {
      left = max(1, i - a[i]);
      right = min(n, i + a[i]);
      if (left == 1 && right == n)
        ++t;
      else {
        for (j = left; j <= right; ++j) {
          ++b[j];
        }
      }
    }
    for (i = 1; i <= n; ++i)
      a[i] = b[i] + t, b[i] = 0;
    if (t == n)
      break;
  }
  print(n);
  return 0;
}
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>;

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: WA

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>;

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

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

#define ll long long
#define VI vector<int>
#define VLL vector<ll>
#define PII pair<int, int>
#define mp make_pair
#define pb push_back
#define PI acos(-1)
#define ld long double
const int MxN = 200001;
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

/* VARIABLES */
int n, k;
VI a(MxN);

/* END OF VARIABLES */

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

  cin >> n >> k;
  FOR(i, 0, n)
  cin >> a[i];
  if (k >= 3 * log2((ld)n)) {
    FOR(i, 0, n)
    cout << n << ' ';
    return 0;
  }
  FOR(i, 0, k) {
    VI tmp(n + 1);
    FOR(j, 0, n) {
      int l = max(0, j - a[j]);
      int r = min(n - 1, j + a[j]);
      tmp[l]++;
      if (r + 1 < n)
        tmp[r + 1]--;
    }
    FOR(j, 1, n) { tmp[j] += tmp[j - 1]; }
    FOR(j, 0, n) { a[j] = tmp[j]; }
  }

  FOR(i, 0, n)
  cout << a[i] << " ";

  return 0;
}


Error: WA

Fixed submission:

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

#define ll long long
#define VI vector<int>
#define VLL vector<ll>
#define PII pair<int, int>
#define mp make_pair
#define pb push_back
#define PI acos(-1)
#define ld long double
const int MxN = 100001;
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

/* VARIABLES */
int n, k;
VI a(MxN);

/* END OF VARIABLES */

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

  cin >> n >> k;
  FOR(i, 0, n)
  cin >> a[i];
  if (k >= 3 * log2((ld)n)) {
    FOR(i, 0, n)
    cout << n << ' ';
    return 0;
  }
  FOR(i, 0, k) {
    VI tmp(n + 1);
    FOR(j, 0, n) {
      int l = max(0, j - a[j]);
      int r = min(n - 1, j + a[j]);
      tmp[l]++;
      if (r + 1 < n)
        tmp[r + 1]--;
    }
    FOR(j, 1, n) { tmp[j] += tmp[j - 1]; }
    FOR(j, 0, n) { a[j] = tmp[j]; }
  }

  FOR(i, 0, n)
  cout << a[i] << " ";

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

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  k = min(k, 100);
  for (int i = 0; i < k; i++) {
    vector<int> b(n + 1);
    for (int j = 0; j < n; j++) {
      int l = max(0, j - a[j]);
      int r = min(n - 1, j + a[j]);
      b[l]++;
      b[r + 1]--;
    }
    for (int j = 0; j < n; j++) {
      b[j + 1] += b[j];
      a[j] = b[j];
    }
  }
  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 main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int it = max(k, (int)floor(log(k)));
  for (int i = 0; i < it; i++) {
    vector<int> b(n + 1);
    for (int j = 0; j < n; j++) {
      int l = max(0, j - a[j]);
      int r = min(n - 1, j + a[j]);
      b[l]++;
      b[r + 1]--;
    }
    for (int j = 0; j < n; j++) {
      b[j + 1] += b[j];
      a[j] = b[j];
    }
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << ' ';
  }
  cout << '\\n';
  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;
using p = pair<int, int>;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  rep(i, 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] << " ";
  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 i = 0; i < n; i++)
    cin >> a.at(i);

  vector<int> b(n);
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n; j++) {
      for (int l = j - a.at(j); l <= j + a.at(j); l++) {
        if (l < 0)
          continue;
        else if (l > n - 1)
          break;
        else
          b.at(l) += 1;
      }
    }

    for (int j = 0; j < n; j++) {
      a.at(j) = b.at(j);
      b.at(j) = 0;
    }
  }

  for (int i = 0; i < n; i++)
    cout << a.at(i) << " ";

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

#include <bits/stdc++.h>
#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 ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
using P = pair<int, int>;
typedef long long ll;

vector<int> to[1000005];

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

  vector<int> A(N);
  REP(i, N) { cin >> A[i]; }

  REP(x, K) {
    vector<int> B(N + 1);
    REP(i, N) {
      int l = max(0, int(i) - A[i]);
      int r = min(int(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] << " "; }
  cout << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#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 ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
using P = pair<int, int>;
typedef long long ll;

vector<int> to[1000005];

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

  int A[N];
  vector<int> B(N, 0);
  REP(i, N) { cin >> A[i]; }

  bool max_flag = false;
  int num;
  FOR(x, 1, K) {
    REP(i, N) {
      int l = max(0, int(i) - A[i]);
      int r = min(N - 1, int(i) + A[i]);
      B[l]++;

      if (r + 1 < N)
        B[r + 1]--;
    }

    FOR(i, 1, N - 1) { B[i] += B[i - 1]; }

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

    if (MIN(B) > log10(N)) {
      max_flag = true;
      break;
    }
  }

  if (max_flag == true) {
    REP(i, N) { B[i] += (K - num) * N; }
  }

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

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

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

  if (k > 41) {
    for (int i = 0; i < n; i++) {
      cout << n;
      if (i < n - 1)
        cout << " ";
    }
  } else {
    for (int K = 0; K < k; K++) {
      vector<int> b(n, 0);
      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];
      if (i < n - 1)
        cout << " ";
    }
  }
}

Error: TLE

Fixed submission:

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

int main(void) {
  int n, k;
  cin >> n >> k;
  int a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = 0;
  }
  for (int K = 0; K < k; K++) {
    for (int i = 0; i < n; i++) {
      int count = 1;
      for (int j = i + 1; j < n; j++) {
        if (a[j] >= abs(i - j))
          count++;
      }
      for (int j = i - 1; j >= 0; j--) {
        if (a[j] >= abs(i - j))
          count++;
      }
      b[i] = max(a[i], count);
    }
    for (int i = 0; i < n; i++)
      a[i] = b[i];
  }

  for (int i = 0; i < n; i++) {
    cout << a[i];
    if (i != n - 1)
      cout << " ";
    else
      cout << endl;
  }
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <math.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++)
using ll = long long;
using vec = vector<int>;
using vec2 = vector<vector<int>>;

int main() {
  int n, k;
  cin >> n >> k;
  vec a(n, 0);
  rep(i, n) { cin >> a[i]; }
  rep(i, k) {
    vec b(n + 1, 0);
    rep(j, n) {
      int f = max(0, j - a[j]);
      int m = min(n, j + a[j] + 1);
      b[f]++;
      b[m]--;
    }
    rep(j, n) { b[j + 1] = b[j] + b[j + 1]; }
    b.pop_back();
    if (a == b) {
      break;
    }
    a = b;
  }
  rep(i, n) { cout << a[i] << " "; }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <math.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++)
using ll = long long;
using vec = vector<int>;
using vec2 = vector<vector<int>>;

int main() {
  int n, k;
  cin >> n >> k;
  vec a(n, 0);
  rep(i, n) { cin >> a[i]; }
  rep(i, k) {
    vec b(n + 1, 0);
    rep(j, n) {
      int k = max(0, i - a[j]);
      int m = min(n + 1, i + a[j] + 1);
      b[k]++;
      b[m]--;
    }
    rep(j, n) { b[j + 1] = b[j] + b[j + 1]; }
    b.pop_back();
    if (b == a) {
      break;
    }
    a = b;
  }
  rep(i, n) { cout << a[i] << endl; }
}