Problem p03717 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ers erase
#define ins insert
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define debug(x) cout << #x << "= " << x << '\n';
#define kill(x) return cout << x, 0;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 2e2 + 10;
const ll INF = 1e18;
const ll LOG = 25;

ll dp[N][N][N], n, m, ans = 0;

vector<pll> SEG[N];

bool isval(ll R, ll G, ll B) {
  ll Cnt = 0;
  if ((R == G && R != 0) || (R == B && R != 0) || (G == B && G != 0))
    return 0;
  for (auto u : SEG[max({R, G, B})]) {
    Cnt = 0;
    if (R >= u.F)
      Cnt++;
    if (G >= u.F)
      Cnt++;
    if (B >= u.F)
      Cnt++;
    if (Cnt != u.S)
      return 0;
  }
  return 1;
}

int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    ll l, r, x;
    cin >> l >> r >> x;
    SEG[r].pb({l, x});
  }
  dp[0][0][0] = 1;
  for (int R = 0; R <= n; R++) {
    for (int G = 0; G <= n; G++) {
      for (int B = 0; B <= n; B++) {
        ll Max = max({R, G, B});
        if (!isval(R, G, B))
          dp[R][G][B] = 0;
        else {
          dp[Max + 1][G][B] += dp[R][G][B];
          dp[R][Max + 1][B] += dp[R][G][B];
          dp[R][G][Max + 1] += dp[R][G][B];
          dp[Max + 1][G][B] %= MOD;
          dp[R][Max + 1][B] %= MOD;
          dp[R][G][Max + 1] %= MOD;
        }
        // cout << R << ' ' << G << ' ' << B << ' ' << dp[R][G][B] << '\n';
      }
    }
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      for (int k = 0; k <= n; k++) {
        if (max({i, j, k}) == n) {
          ans += dp[i][j][k];
          ans %= MOD;
        }
      }
    }
  }
  cout << ans;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ers erase
#define ins insert
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define debug(x) cout << #x << "= " << x << '\n';
#define kill(x) return cout << x, 0;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 3e2 + 10;
const ll INF = 1e18;
const ll LOG = 25;

ll dp[N][N][N], n, m, ans = 0;

vector<pll> SEG[N];

bool isval(ll R, ll G, ll B) {
  ll Cnt = 0;
  if ((R == G && R != 0) || (R == B && R != 0) || (G == B && G != 0))
    return 0;
  for (auto u : SEG[max({R, G, B})]) {
    Cnt = 0;
    if (R >= u.F)
      Cnt++;
    if (G >= u.F)
      Cnt++;
    if (B >= u.F)
      Cnt++;
    if (Cnt != u.S)
      return 0;
  }
  return 1;
}

int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    ll l, r, x;
    cin >> l >> r >> x;
    SEG[r].pb({l, x});
  }
  dp[0][0][0] = 1;
  for (int R = 0; R <= n; R++) {
    for (int G = 0; G <= n; G++) {
      for (int B = 0; B <= n; B++) {
        ll Max = max({R, G, B});
        if (!isval(R, G, B))
          dp[R][G][B] = 0;
        else {
          dp[Max + 1][G][B] += dp[R][G][B];
          dp[R][Max + 1][B] += dp[R][G][B];
          dp[R][G][Max + 1] += dp[R][G][B];
          dp[Max + 1][G][B] %= MOD;
          dp[R][Max + 1][B] %= MOD;
          dp[R][G][Max + 1] %= MOD;
        }
        // cout << R << ' ' << G << ' ' << B << ' ' << dp[R][G][B] << '\n';
      }
    }
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      for (int k = 0; k <= n; k++) {
        if (max({i, j, k}) == n) {
          ans += dp[i][j][k];
          ans %= MOD;
        }
      }
    }
  }
  cout << ans;

  return 0;
}