Problem p02983 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define cina(s, n, a)                                                          \
  for (int i = s; i < n; i++)                                                  \
  cin >> a[i]
#define couta(n, a)                                                            \
  for (int i = 0; i < n; i++)                                                  \
  cout << a[i] << ' '
#define copy(s, n, a, b)                                                       \
  for (int i = s; i < n; i++)                                                  \
  b[i] = a[i]
#define yesno(ok) cout << (ok ? "YES" : "NO")
#define mod(a, b) (b + (a % b)) % b
#define MOD (int)1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::vector<pii> vpii;
using namespace std;

void solve() {
  ll x, y;
  cin >> x >> y;
  if (x - y > 2019) {
    cout << 2;
  } else {
    ll ans = INT_MAX;
    for (ll i = x; i <= y; i++) {
      for (ll j = x; j <= y; j++) {
        if (i != j)
          ans = min(ans, (i * j) % 2019);
      }
    }
    cout << ans;
  }
}

int main() {
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int q = 1;
  // cin >> q;
  for (int i = 1; i <= q; i++) {
    solve();
  }
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define cina(s, n, a)                                                          \
  for (int i = s; i < n; i++)                                                  \
  cin >> a[i]
#define couta(n, a)                                                            \
  for (int i = 0; i < n; i++)                                                  \
  cout << a[i] << ' '
#define copy(s, n, a, b)                                                       \
  for (int i = s; i < n; i++)                                                  \
  b[i] = a[i]
#define yesno(ok) cout << (ok ? "YES" : "NO")
#define mod(a, b) (b + (a % b)) % b
#define MOD (int)1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::vector<pii> vpii;
using namespace std;

void solve() {
  ll x, y;
  cin >> x >> y;
  if (abs(x - y) > 2019) {
    cout << 0;
  } else {
    ll ans = INT_MAX;
    for (ll i = x; i <= y; i++) {
      for (ll j = x; j <= y; j++) {
        if (i != j)
          ans = min(ans, (i * j) % 2019);
      }
    }
    cout << ans;
  }
}

int main() {
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int q = 1;
  // cin >> q;
  for (int i = 1; i <= q; i++) {
    solve();
  }
}