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

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set                                                                  \\
  tree<int, null_type, less<int>, rb_tree_tag,                                 \\
       tree_order_statistics_node_update>
#define o_setll                                                                \\
  tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
// 1. order_of_key(k) : number of elements strictly lesser than k
// 2. find_by_order(k) : k-th element in the set

int main() {
  string s;
  cin >> s;
  ll n = s.size();

  ll dp[2020][2];
  REP(i, 0, 2) {
    REP(j, 0, 2020) { dp[j][i] = 0; }
  }

  dp[s[0] - '0'][0] = 1;
  REP(i, 0, 2) dp[0][i] = 1;

  ll curr = 1;
  ll sum = 1;

  REP(i, 1, n) {

    REP(j, 0, 2019) {
      ll v = ((10 * j + s[i] - '0') % 2019);
      dp[v][curr] += dp[j][curr ^ 1];
    }
    sum += dp[0][curr];

    curr ^= 1;

    REP(j, 0, 2019) { dp[j][curr] = 0; }
    dp[0][curr] = 1;
  }

  cout << sum - n << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set                                                                  \\
  tree<int, null_type, less<int>, rb_tree_tag,                                 \\
       tree_order_statistics_node_update>
#define o_setll                                                                \\
  tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
// 1. order_of_key(k) : number of elements strictly lesser than k
// 2. find_by_order(k) : k-th element in the set

int main() {
  string s;
  cin >> s;
  ll n = s.size();

  ll dp[2020][n];
  REP(i, 0, n) {
    REP(j, 0, 2020) { dp[j][i] = 0; }
  }

  dp[s[0] - '0'][0] = 1;
  REP(i, 0, n) dp[0][i] = 1;

  REP(i, 1, n) {

    // dp[s[i]-'0'][i]++;
    REP(j, 0, 2019) {
      ll v = ((10 * j + s[i] - '0') % 2019);
      dp[v][i] += dp[j][i - 1];
    }
  }
  ll sum = 0;
  REP(i, 0, n) { sum += dp[0][i]; }
  cout << sum - n << endl;
  return 0;
}