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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define PI acos(-1.0)
#define ALL(A) ((A).begin(), (A).end())
#define vsort(v) sort(v.begin(), v.end())
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)

int main() {
  int N, K;
  cin >> N >> K;
  int pasta[N + 1];
  FOR(i, 0, N + 1) pasta[i] = 0;
  FOR(i, 1, K + 1) {
    int hi, pas;
    cin >> hi >> pas;
    pasta[hi] = pas;
  }
  ll int dp[N + 1][4][4];
  FOR(i, 0, N + 1) {
    FOR(j, 0, 4) {
      FOR(k, 0, 4) { dp[i][j][k] = 0; }
    }
  }
  FOR(i, 1, 4) {
    if (pasta[1] == 0) {
      dp[1][i][0] = 1;
    } else {
      if (i == pasta[1])
        dp[1][i][0] = 1;
    }
  }

  FOR(i, 1, N + 1) {
    FOR(j, 0, 4) {
      FOR(k, 0, 4) {
        if (dp[i][j][k] == 0)
          continue;
        FOR(m, 1, 4) {
          if (j == k && m == k)
            continue;
          if (pasta[i + 1] == 0) {
            dp[i + 1][m][j] = dp[i + 1][m][j] + dp[i][j][k];
            dp[i + 1][m][j] %= 10000;
          } else {
            if (pasta[i + 1] == m) {
              dp[i + 1][m][j] = dp[i + 1][m][j] + dp[i][j][k];
              dp[i + 1][m][j] %= 10000;
            }
            // else dp[i+1][m][j] = 0;
          }
        }
      }
    }
  }
  ll int ans = 0;
  FOR(i, 1, 4) {
    FOR(j, 1, 4) {
      ans += dp[N][i][j];
      ans = ans % 10000;
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

/*********************************************************************\\
                                                                      |
    codeforces = nenuon  ||  Atcoder = nenuon                         |
    mail = keep.my.best.61@gmail.com                                  |
    Tokyo Metropolitan University                                     |
                                                                      |
**********************************************************************/

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define PI acos(-1.0)
#define ALL(A) ((A).begin(), (A).end())
#define vsort(v) sort(v.begin(), v.end())
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)

int main() {
  int N, K;
  cin >> N >> K;
  int pasta[100 + 1] = {0};
  FOR(i, 1, K + 1) {
    int hi, pas;
    cin >> hi >> pas;
    pasta[hi] = pas;
  }
  int dp[100 + 1][4][4] = {0};
  FOR(i, 1, 4) {
    if (pasta[1] == 0) {
      dp[1][i][0] = 1;
    } else {
      if (i == pasta[1])
        dp[1][i][0] = 1;
    }
  }

  FOR(i, 1, N + 1) {
    FOR(j, 0, 4) {
      FOR(k, 0, 4) {
        if (dp[i][j][k] == 0)
          continue;
        FOR(m, 1, 4) {
          if (j == k && m == k)
            continue;
          if (pasta[i + 1] == 0) {
            dp[i + 1][m][j] = dp[i + 1][m][j] + dp[i][j][k];
          } else {
            if (pasta[i + 1] == m) {
              dp[i + 1][m][j] = dp[i + 1][m][j] + dp[i][j][k];
            }
            // else dp[i+1][m][j] = 0;
          }
        }
      }
    }
  }
  int ans = 0;
  FOR(i, 1, 4) {
    FOR(j, 1, 4) {
      ans += dp[N][i][j];
      ans = ans % 10000;
    }
  }

  cout << ans << endl;
}