Problem p02983 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

#define REP1(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define pow(x) x *x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;

struct edge {
  ll to;
  char cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int N;

int main(void) {

  ll L, R;
  cin >> L >> R;
  const int _mod = 2019;
  ll modL = L % _mod;
  ll modR = R % _mod;
  ll diff = (R / _mod) - (L / _mod);

  int ans = _mod;
  for (int i = L; i < R; i++) {
    for (int j = L + 1; j <= R; j++) {
      ans = min(ans, ((i % _mod) * (j % _mod) % _mod));
      if (ans == 0)
        break;
      // cout << i << " " << j <<  endl;
    }
  }

  cout << ans << endl;
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define REP1(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define pow(x) x *x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;

struct edge {
  ll to;
  char cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int N;

int main(void) {

  ll L, R;
  cin >> L >> R;
  const int _mod = 2019;

  if (R - L > 1e4) {
    cout << 0 << endl;
    return 0;
  }

  int ans = _mod;
  for (int i = L; i < R; i++) {
    for (int j = L + 1; j <= R; j++) {
      ans = min(ans, ((i % _mod) * (j % _mod) % _mod));
      if (ans == 0)
        break;
      // cout << i << " " << j <<  endl;
    }
  }

  cout << ans << endl;
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/