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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
// container util

//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define MT(a, b, c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

const LL MOD = 1000000009;
int zz;
LL pe[100][10000];

void mulmatmat(LL *l, LL *r, LL *ans) {
  REP(i, zz) {
    FOR(j, i, zz) {
      REP(k, zz) {
        ans[i * 75 + j] =
            (ans[i * 75 + j] + l[i * 75 + k] * r[k * 75 + j]) % MOD;
      }
      ans[j * 75 + i] = ans[i * 75 + j];
    }
  }
}

VLL mulmatvec(LL *l, VLL r) {
  VLL ans(zz, 0LL);
  REP(i, zz) {
    REP(j, zz) {
      ans[i] += l[i * 75 + j] * r[j];
      ans[i] %= MOD;
    }
  }
  return ans;
}

VLL mulmatvec(LL k, VLL r) {
  int i = 0;
  VLL tr = r;
  while (k) {
    if (k & 1) {
      tr = mulmatvec(pe[i], tr);
    }
    k >>= 1;
    i++;
  }
  return tr;
}

int main() {
  int t = 1;
  LL h, nb;
  while (scanf("%d%lld%lld", &zz, &h, &nb), zz) {
    map<LL, VI> bar;
    VLL bary;
    memset(pe, 0, sizeof(pe));
    REP(i, zz) FOR(j, max(0, i - 1), min(zz, i + 2)) pe[0][i * 75 + j] = 1LL;
    REP(i, 65) mulmatmat(pe[i], pe[i], pe[i + 1]);
    REP(i, nb) {
      LL bx, by;
      scanf("%lld%lld", &bx, &by);
      bar[by].PB(bx);
      bary.PB(by);
    }
    bary.PB(h);
    SORT(bary);
    LL cur = 1;
    VLL vec(zz, 0);
    vec[0] = 1LL;
    REP(i, bary.size()) {
      LL p = bary[i] - cur;
      cur = bary[i];
      vec = mulmatvec(p, vec);
      REP(j, bar[cur].size()) vec[bar[cur][j] - 1] = 0LL;
    }
    printf("Case %d: %lld\\n", t++, vec[zz - 1]);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
// container util

//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define MT(a, b, c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000009LL

int zz;
LL pe[100][10000];

void mulmatmat(LL *l, LL *r, LL *ans) {
  REP(i, zz) {
    FOR(j, i, zz) {
      REP(k, zz) {
        ans[i * 75 + j] =
            (ans[i * 75 + j] + l[i * 75 + k] * r[k * 75 + j]) % MOD;
      }
      ans[j * 75 + i] = ans[i * 75 + j];
    }
  }
}

VLL mulmatvec(LL *l, VLL r) {
  VLL ans(zz, 0LL);
  REP(i, zz) {
    REP(j, zz) {
      ans[i] += l[i * 75 + j] * r[j];
      ans[i] %= MOD;
    }
  }
  return ans;
}

VLL mulmatvec(LL k, VLL r) {
  int i = 0;
  VLL tr = r;
  while (k) {
    if (k & 1) {
      tr = mulmatvec(pe[i], tr);
    }
    k >>= 1;
    i++;
  }
  return tr;
}

int main() {
  int t = 1;
  LL h, nb;
  while (scanf("%d%lld%lld", &zz, &h, &nb), zz) {
    map<LL, VI> bar;
    VLL bary;
    memset(pe, 0, sizeof(pe));
    REP(i, zz) FOR(j, max(0, i - 1), min(zz, i + 2)) pe[0][i * 75 + j] = 1LL;
    REP(i, 65) mulmatmat(pe[i], pe[i], pe[i + 1]);
    REP(i, nb) {
      LL bx, by;
      scanf("%lld%lld", &bx, &by);
      bar[by].PB(bx);
      bary.PB(by);
    }
    bary.PB(h);
    SORT(bary);
    unique(ALL(bary));
    LL cur = 1;
    VLL vec(zz, 0);
    vec[0] = 1LL;
    REP(i, bary.size()) {
      LL p = bary[i] - cur;
      cur = bary[i];
      vec = mulmatvec(p, vec);
      REP(j, bar[cur].size()) vec[bar[cur][j] - 1] = 0LL;
    }
    printf("Case %d: %lld\\n", t++, vec[zz - 1]);
  }
  return 0;
}