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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template <typename T> istream &operator>>(istream &is, vector<T> &vs) {
  for (T &v : vs)
    is >> v;
  return is;
}

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vs) {
  for (const T &v : vs)
    os << v << " ";
  return os;
}

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

  for (int i = 0; i < K; ++i) {
    vector<int> tmp(N + 1, 0);
    for (int j = 0; j < N; ++j) {
      int start = max(0, j - A[j]);
      int end = min(N - 1, j + A[j]);
      ++tmp[start];
      --tmp[end + 1];
    }
    int sum = 0;
    bool all_max = true;
    for (int j = 0; j < N; ++j) {
      sum += tmp[j];
      A[j] = sum;
      if (A[j] < N)
        all_max = false;
    }
    if (all_max)
      break;
  }
  cout << A << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template <typename T> istream &operator>>(istream &is, vector<T> &vs) {
  for (T &v : vs)
    is >> v;
  return is;
}

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vs) {
  for (const T &v : vs)
    os << v << " ";
  return os;
}

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

  for (int i = 0; i < K; ++i) {
    vector<int> tmp(N + 1, 0);
    for (int j = 0; j < N; ++j) {
      int start = max(0, j - A[j]);
      int end = min(N - 1, j + A[j]);
      ++tmp[start];
      --tmp[end + 1];
    }
    int sum = 0;
    for (int j = 0; j < N; ++j) {
      sum += tmp[j];
      A[j] = sum;
    }
  }
  cout << A << endl;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

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

int A[200005];
int B[200005];

int ft[200005];

int rsq(int b) {
  int res = 0;
  while (b) {
    res += ft[b];
    b -= b & (-b);
  }
  return res;
}

void update(int k, int v) {
  while (k <= 200002) {
    ft[k] += v;
    k += k & (-k);
  }
}

void update2(int a, int b, int v) {
  update(a, v);
  update(b + 1, -v);
}

int main() {
  int N, K;
  scanf("%d%d", &N, &K);

  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }

  for (int i = 0; i < K; i++) {
    memset(ft, 0, sizeof(ft));
    for (int j = 0; j < N; j++) {
      update2(1 + max(j - A[j], 0), 1 + min(j + A[j], N - 1), 1);
    }

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

    bool canStop = true;
    for (int j = 0; j < N; j++) {
      if (A[j] != N) {
        canStop = false;
        break;
      }
    }

    if (canStop) {
      break;
    }

    /*for(int j = 0; j < N; j ++){
        printf("%d ", A[j]);
    }
    printf("\\n");*/
  }

  for (int j = 0; j < N; j++) {
    printf("%d ", A[j]);
  }
  printf("\\n");

  return 0;
}


Error: WA

Fixed submission:

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

int A[100005];
int B[100005];

int ft[100005];

int rsq(int b) {
  int res = 0;
  while (b) {
    res += ft[b];
    b -= b & (-b);
  }
  return res;
}

void update(int k, int v) {
  while (k <= 100002) {
    ft[k] += v;
    k += k & (-k);
  }
}

void update2(int a, int b, int v) {
  update(a, v);
  update(b + 1, -v);
}

int main() {
  int N, K;
  scanf("%d%d", &N, &K);

  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }

  for (int i = 0; i < K; i++) {
    memset(ft, 0, sizeof(ft));
    for (int j = 0; j < N; j++) {
      update2(1 + max(j - A[j], 0), 1 + min(j + A[j], N - 1), 1);
    }

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

    if (K > 50) {
      break;
    }

    /*for(int j = 0; j < N; j ++){
        printf("%d ", A[j]);
    }
    printf("\\n");*/
  }

  for (int j = 0; j < N; j++) {
    printf("%d ", A[j]);
  }
  printf("\\n");

  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

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

#define watch(x) cerr << (#x) << ": " << (x) << endl

typedef long long LL;

const int N = 200009;
int n, k, a[N], b[N];

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

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

  LL tot = 0, mx = (LL)n * n;
  for (int i = 0; i < n; ++i) {
    b[i] = a[i];
    tot += b[i];
  }

  for (int i = 0; i < k && tot < mx; ++i) {
    vector<int> rg(n + 1, 0);
    for (int j = 0; j < n; ++j) {
      int l = max(0, j - b[j]), r = min(n, j + b[j] + 1);
      rg[l]++;
      rg[r]--;
    }

    int cur = 0;
    tot = 0LL;
    for (int j = 0; j < n; ++j) {
      cur += rg[j];
      b[j] = cur;
      tot += b[j];
    }
  }

  for (int i = 0; i < n; ++i) {
    cout << b[i] << ' ';
  }
  cout << '\\n';

  return 0;
}


Error: WA

Fixed submission:

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

#define watch(x) cerr << (#x) << ": " << (x) << endl

typedef long long LL;

const int N = 200009;
int n, k, a[N], b[N];

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

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

  LL tot = 0, mx = (LL)n * n;
  for (int i = 0; i < n; ++i) {
    b[i] = a[i];
    tot += b[i];
  }

  for (int i = 0; i < k && tot < mx; ++i) {
    vector<int> rg(n, 0);
    for (int j = 0; j < n; ++j) {
      int l = max(0, j - b[j]), r = min(n, j + b[j] + 1);
      rg[l]++;
      rg[r]--;
    }

    int cur = 0;
    for (int j = 0; j < n; ++j) {
      cur += rg[j];
      b[j] = cur;
      tot += b[j];
    }
  }

  for (int i = 0; i < n; ++i) {
    cout << b[i] << ' ';
  }
  cout << '\\n';

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void) {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  rep(j, 0, min(k, 50)) {
    vector<ll> b(n + 1, 0);
    rep(i, 0, n) {
      int x = max((ll)0, i - a[i]);
      int y = min((ll)n, i + a[i] + 1);
      b[x]++;
      b[y]--;
    }

    rep(i, 0, n) b[i + 1] += b[i];
    b.pop_back();
    if (a == b)
      break;
    a = b;
  }
  rep(i, 0, n) cout << a[i] << " ";
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void) {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  vector<ll> b(n, 0);
  rep(l, 0, k) {
    rep(i, 0, n) b[i] = 0;
    rep(i, 0, n) {
      b[i]++;
      rep(j, 0, a[i]) {
        if (i - j - 1 >= 0 && i - j - 1 < n)
          b[i - j - 1]++;
        if (i + j + 1 >= 0 && i + j + 1 < n)
          b[i + j + 1]++;
      }
    }
    rep(i, 0, n) a[i] = b[i];
    if (MX(a) == n && MN(a) == n)
      break;
  }
  rep(i, 0, n) cout << a[i] << " ";
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define DIV 998244353

using namespace std;
using ll = long long;
using ldb = long double;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  if (N <= K) {
    for (int i = 0; i < N; i++) {
      cout << N << " ";
    }
    cout << endl;
  } else {
    for (int i = 0; i < min(K, (ll)100); i++) {
      vector<ll> im(N);
      for (int j = 0; j < N; j++) {
        im[max((ll)0, j - a[j])]++;
        if (j + a[j] + 1 < N)
          im[j + a[j] + 1]--;
      }
      ll temp = 0;
      for (int k = 0; k < N; k++) {
        // cout << im[k] << endl;
        temp += im[k];
        a[k] = temp;
      }
    }
    for (int i = 0; i < N; i++)
      cout << min(N, a[i]) << " ";
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define DIV 998244353

using namespace std;
using ll = long long;
using ldb = long double;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  if (N <= K) {
    for (int i = 0; i < N; i++) {
      cout << N << " ";
    }
    cout << endl;
  } else {
    for (int i = 0; i < K; i++) {
      vector<ll> im(N);
      for (int j = 0; j < N; j++) {
        im[max((ll)0, j - a[j])]++;
        if (j + a[j] + 1 < N)
          im[j + a[j] + 1]--;
      }
      ll temp = 0;
      for (int k = 0; k < N; k++) {
        temp += im[k];
        a[k] = temp;
      }
    }
    for (int i = 0; i < N; i++)
      cout << a[i] << " ";
    cout << endl;
  }
}
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 rep3(i, m, n) for (int(i) = m; (i) <= (n); (i)++)
#define rep3rev(i, m, n) for (int(i) = m; (i) >= (n); (i)--)
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

int min(vi x) {
  sort(all(x));
  return x[0];
}

void Main() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i, n) cin >> a[i];

  rep(kk, k) {
    vi b(n, 0);
    rep(i, n) {
      int l = max(0, i - a[i]);
      int r = min(n - 1, i + a[i]);
      b[l]++;
      if (r + 1 < n)
        b[r + 1]--;
    }
    rep3(i, 1, n - 1) { b[i] += b[i - 1]; }

    if (min(b) == n) {
      rep(i, n) cout << b[i] << " ";
      cout << endl;
      return;
    }
    a = b;
  }

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

  return;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Error: TLE

Fixed submission:

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

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep3(i, m, n) for (int(i) = m; (i) <= (n); (i)++)
#define rep3rev(i, m, n) for (int(i) = m; (i) >= (n); (i)--)
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main() {
  int n, k;
  cin >> n >> k;
  vi a(n), check(n, n);

  rep(i, n) cin >> a[i];

  auto f = [&](vi x) {
    vi b(n, 0);
    rep(i, n) {
      rep3(d, max(i - n + 1, -x[i]), min(i, x[i])) { b[i - d]++; }
    }
    return b;
  };

  rep(kk, k) {
    vi na = f(a);
    /*
    cout << "now: " << kk+1 << endl;
    rep(i, n) cout << a[i] << " ";
    cout << endl;
    //*/
    if (na == check) {
      rep(i, n) cout << check[i] << " ";
      cout << endl;
      return;
    }
    a = na;
  }

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

  return;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  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++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;

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) {
    if (i > 0)
      cout << " ";
    cout << a[i];
  }
  cout << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<vector<ll>> a(k + 5, vector<ll>(n + 5, 0));
  rep(i, n) { cin >> a[0][i]; }
  ll it = 0;
  while (k--) {
    int cnt = 0;
    rep(i, n) {
      if (a[it][i] == n)
        cnt++;
      a[it + 1][i]++;
      for (int j = 1; j <= a[it][i]; j++) {
        if (0 <= i - j) {
          a[it + 1][i - j]++;
        }
        if (i + j <= n - 1) {
          a[it + 1][i + j]++;
        }
      }
    }
    if (cnt == n) {
      break;
    }
    it++;
  }
  rep(i, n) {
    cout << a[it][i] << " ";
    if (i == n - 1)
      cout << endl;
  }
}
Problem p02647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define FOR(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)

#define MOD 1000000007
#define INF 1000000000

using ll = long long int;
using namespace std;

typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
  int N, K;
  cin >> N >> K;
  vi A(N);
  rep(i, N) cin >> A[i];

  rep(i, K) {
    bool flag = true;
    vi B(N, 0);
    rep(j, N) {
      if (flag && A[j] < N)
        flag = false;
      B[max(0, (int)j - A[j])]++;
      if ((int)j + A[j] < N - 1)
        B[(int)j + A[j] + 1]--;
    }

    rep(j, N - 1) B[j + 1] += B[j];
    rep(j, N) A[j] = B[j];
    if (flag)
      break;
  }

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define FOR(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)

#define MOD 1000000007
#define INF 1000000000

using ll = long long int;
using namespace std;

typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
  int N, K;
  cin >> N >> K;
  vi A(N);
  rep(i, N) cin >> A[i];

  rep(i, K) {
    bool flag = true;
    vi B(N, 0);
    rep(j, N) {
      if (flag && A[j] != N - 1)
        flag = false;
      B[max(0, (int)j - A[j])]++;
      if ((int)j + A[j] < N - 1)
        B[(int)j + A[j] + 1]--;
    }

    rep(j, N - 1) B[j + 1] += B[j];
    rep(j, N) A[j] = B[j];
    if (flag)
      break;
  }

  rep(i, N) { cout << A[i] << "\\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(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[i + 1];
    b.pop_back();
    if (a == b)
      break;
    a = b;
  }
  rep(i, n) cout << a[i] << endl;
}


Error: TLE

Fixed submission:

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

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

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

  vector<int> c(N + 1);
  // float under;
  // float upper;
  int under;
  int upper;

  for (int i = 0; i < K; i++) {
    for (int j = 1; j <= N; j++) {
      // under = j - A.at(j) - 0.5 ;
      under = j - A.at(j);
      // upper = j + A.at(j) + 0.5 ;
      upper = j + A.at(j);
      for (int k = 1; k <= N; k++) {
        if (under <= k && k <= upper) {
          c.at(k)++;
        }
      }
    }
    for (int j = 1; j <= N; j++) {
      A.at(j) = c.at(j);
      c.at(j) = 0;
    }
  }
  for (int i = 1; i <= N; i++) {
    cout << A.at(i) << ' ';
  }
  cout << endl;

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

  // for (int i = 1; i <= N; i++)
  //{
  //   cout << "c.at(" << i << ") = " << c.at(i) << endl;
  // }
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <numeric>

const int MaxN = 200005;

int n, A[MaxN];

bool trans() {
  static int B[MaxN];
  std::fill(B, B + n, 0);
  for (int i = 0; i < n; ++i) {
    int l = std::max(0, i - A[i]);
    int r = std::min(n - 1, i + A[i]);
    B[l] += 1;
    B[r + 1] -= 1;
  }
  bool flag = true;
  for (int i = 0; i < n; ++i) {
    flag &= A[i] == B[i];
    A[i] = B[i];
    B[i + 1] += B[i];
  }
  return flag;
}

int main() {
  int q;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; ++i)
    scanf("%d", A + i);
  while (q--) {
    if (trans())
      break;
  }
  for (int i = 0; i < n; ++i)
    printf("%d ", A[i]);
  puts("");
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <numeric>

const int MaxN = 100005;

int n, A[MaxN];

bool trans() {
  static int B[MaxN];
  std::fill(B, B + n, 0);
  for (int i = 0; i < n; ++i) {
    int l = std::max(0, i - A[i]);
    int r = std::min(n - 1, i + A[i]);
    B[l] += 1;
    B[r + 1] -= 1;
  }
  bool flag = true;
  for (int i = 0; i < n; ++i) {
    flag &= A[i] == B[i];
    A[i] = B[i];
    B[i + 1] += B[i];
  }
  return flag;
}

int main() {
  int q;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; ++i)
    scanf("%d", A + i);
  while (q--) {
    if (trans())
      break;
  }
  for (int i = 0; i < n; ++i)
    printf("%d ", A[i]);
  puts("");
  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() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  bool pend = false;
  int count = 0;
  while (--k >= 0 && pend == false) {
    vector<ll> b(n + 1);
    rep(i, n) {
      int l = max(0ll, 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];
    if (i < n - 1)
      cout << " ";
    else
      cout << endl;
  }
  return 0;
}
/* 小手先の時間短縮では収まっていない。やり型そのものに欠陥がある。*/


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;
using P = pair<int, int>;

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

  bool pend = false;
  int count = 0;
  while (--k >= 0 && pend == false) {
    vector<int> dp(n);
    rep(i, n) {
      ll d = a[i];
      if (d < n) {
        for (int j = max(0ll, -d + i); j <= min(n - 1, d + i); j++) {
          dp[j]++;
        }
      } else {
        count++;
      }
    }
    rep(i, n) dp[i] += count;
    pend = true;
    rep(i, n) {
      a[i] = dp[i];
      if (a[i] < n)
        pend = false;
    }
  }
  rep(i, n) {
    cout << a[i];
    if (i < n - 1)
      cout << " ";
    else
      cout << endl;
  }
  return 0;
}
Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a && (a = b, true);
}
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a, x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for (int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
#define stp(x) setprecision(x)
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vint a(n);
  rep(i, n) { cin >> a[i]; }
  if (k > 100) {
    rep(i, n) { cout << n << ' '; }
  } else {
    rep(i, k) {
      vector<int> imos(n);
      rep(i, n) {
        if (i - a[i] < 0) {
          imos[0]++;
        } else {
          imos[i - a[i]]++;
        }
        if (i + a[i] + 1 >= n) {
        } else {
          imos[i + a[i] + 1]--;
        }
      }
      int count = 0;
      rep(i, n) {
        count += imos[i];
        a[i] = count;
      }
    }
    rep(i, n) { cout << a[i] << ' '; }
  }
  return (0);
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a && (a = b, true);
}
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a, x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for (int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
#define stp(x) setprecision(x)
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  vint a(n);
  cin >> n >> k;
  rep(i, n) { cin >> a[i]; }
  if (k > 100) {
    rep(i, n) { cout << n << ' '; }
  } else {
    rep(i, k) {
      vector<int> imos(n);
      rep(i, n) {
        if (i - a[i] < 0) {
          imos[0]++;
        } else {
          imos[i - a[i]]++;
        }
        if (i + a[i] + 1 >= n) {
        } else {
          imos[i + a[i] + 1]--;
        }
      }
      int count = 0;
      rep(i, n) {
        count += imos[i];
        a[i] = count;
      }
    }
    rep(i, n) { cout << a[i] << ' '; }
  }
  return (0);
}