Problem p02602 (C++) — buggy submission, verdict: Runtime Error



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

using db = double;
using ll = long long;
using ull = unsigned long long;
using pII = pair<int, int>;
using pLL = pair<ll, ll>;

#define F first
#define S second
#define MP make_pair
#define PB push_back
#define deb(X) cout << (X) << endl
#define ASH(X) cout << (X) << " "
#define aLL(X) X.begin(), X.end()
#define vLL(X) array<ll, X>
#define s(X) ((ll)(X).size())
#define deb1(x) cout << #x << " " << x << endl;
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl;
#define deb3(x, y, z)                                                          \\
  cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z     \\
       << endl;
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define RFOR(I, B, A) for (ll I = (B); I >= (A); I--)
#define mem0(X) memset((X), 0, sizeof((X)))
#define mem1(X) memset((X), -1, sizeof((X)))
#define BS(v, x) binary_search(v.begin(), v.end(), x)
#define SORT(c) (sort(c.begin(), c.end()))
#define Time                                                                   \\
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "sec \\n"
#define SORT_UNIQUE(c)                                                         \\
  (sort(c.begin(), c.end()),                                                   \\
   c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
#define CASES                                                                  \\
  int ___T;                                                                    \\
  cin >> ___T;                                                                 \\
  for (int cs = 1; cs <= ___T; cs++)
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

/************************************************/

void Solve() {
  ll n, k;
  cin >> n >> k;
  vector<ll> A(n, 0);
  FOR(i, 0, n - 1) { cin >> A[i]; }

  FOR(i, 0, n - k - 1) {
    if (A[i] < A[i + k]) {
      cout << "Yes\\n";
    } else {
      cout << "No\\n";
    }
  }
}

int32_t main() { Solve(); }


Error: 0

Fixed submission:



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

using db = double;
using ll = long long;
using ull = unsigned long long;
using pII = pair<int, int>;
using pLL = pair<ll, ll>;

#define F first
#define S second
#define MP make_pair
#define PB push_back
#define deb(X) cout << (X) << endl
#define ASH(X) cout << (X) << " "
#define aLL(X) X.begin(), X.end()
#define vLL(X) array<ll, X>
#define s(X) ((ll)(X).size())
#define deb1(x) cout << #x << " " << x << endl;
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl;
#define deb3(x, y, z)                                                          \\
  cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z     \\
       << endl;
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define RFOR(I, B, A) for (ll I = (B); I >= (A); I--)
#define mem0(X) memset((X), 0, sizeof((X)))
#define mem1(X) memset((X), -1, sizeof((X)))
#define BS(v, x) binary_search(v.begin(), v.end(), x)
#define SORT(c) (sort(c.begin(), c.end()))
#define Time                                                                   \\
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "sec \\n"
#define SORT_UNIQUE(c)                                                         \\
  (sort(c.begin(), c.end()),                                                   \\
   c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
#define CASES                                                                  \\
  int ___T;                                                                    \\
  cin >> ___T;                                                                 \\
  for (int cs = 1; cs <= ___T; cs++)
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

/************************************************/

void Execute() {
  ll n, nb, val, q, a, b, k, c, l, r, d, x, y = 1, p, m;
  cin >> n >> k;
  ll ar[n];
  FOR(i, 1, n) cin >> ar[i];

  x = 1;
  FOR(i, 1, k) { x = x * ar[i] * 1LL; }
  FOR(i, 2, k) {

    if (n - i <= k - 1) {

      FOR(j, i, k + i - 1) { y = y * ar[j]; }
    }
    // deb2(x,y);

    if (y < x) {
      deb("Yes");
      x = y;

    } else
      deb("No");
  }
}

int32_t main() { Execute(); }