alexjercan/bugnet huggingface dataset:
Problem p00470 (C++) — buggy submission, verdict: Runtime Error

#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

int main() {
  int w, h;
  while (cin >> w >> h && h | w) {
    static int dp[111][111][4];
    for (int i = 0; i < 111; i++)
      for (int j = 0; j < 111; j++)
        for (int k = 0; k < 4; k++)
          dp[i][j][k] = 0;
    for (int i = 0; i < h; i++)
      dp[i][0][0] = 1;
    for (int i = 0; i < w; i++)
      dp[0][i][2] = 1;
    for (int i = 1; i < h; i++) {
      for (int j = 1; j < w; j++) {
        if (i - 1 >= 0)
          dp[i][j][0] += dp[i - 1][j][0] + dp[i - 1][j][1];
        if (i - 1 >= 0)
          dp[i][j][1] += dp[i - 1][j][2];
        if (j - 1 >= 0)
          dp[i][j][2] += dp[i][j - 1][2] + dp[i][j - 1][3];
        if (j - 1 >= 0)
          dp[i][j][3] += dp[i][j - 1][0];
        for (int k = 0; k < 4; k++)
          dp[i][j][k] %= 100000;
      }
    }

    int ans = 0;
    for (int i = 0; i < 4; i++)
      ans += dp[h - 1][w - 1][i];
    cout << ans % 100000 << endl;
  }
}

Error: WA

Fixed submission:

#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

int main() {
  int w, h;
  while (cin >> w >> h) {
    static int dp[111][111][4];
    for (int i = 0; i < 111; i++)
      for (int j = 0; j < 111; j++)
        for (int k = 0; k < 4; k++)
          dp[i][j][k] = 0;
    for (int i = 0; i < h; i++)
      dp[i][0][0] = 1;
    for (int i = 0; i < w; i++)
      dp[0][i][2] = 1;
    for (int i = 1; i < h; i++) {
      for (int j = 1; j < w; j++) {
        if (i - 1 >= 0)
          dp[i][j][0] += dp[i - 1][j][0] + dp[i - 1][j][1];
        if (i - 1 >= 0)
          dp[i][j][1] += dp[i - 1][j][2];
        if (j - 1 >= 0)
          dp[i][j][2] += dp[i][j - 1][2] + dp[i][j - 1][3];
        if (j - 1 >= 0)
          dp[i][j][3] += dp[i][j - 1][0];
        for (int k = 0; k < 4; k++)
          dp[i][j][k] %= 100000;
      }
    }

    int ans = 0;
    for (int i = 0; i < 4; i++)
      ans += dp[h - 1][w - 1][i];
    cout << ans % 100000 << endl;
  }
}
Problem p00470 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdio>
#include <cstdlib>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
  int h, w;
  while (cin >> w >> h) {
    if (w == 0 && h == 0)
      break;
    int dp[200][200][4] = {}, ans = 0;
    // 0　１つ前で曲がらずに下から来て
    // 1   曲がって下から
    // 2  １つ前で曲がらずに左から来る
    // 3   曲がって左から
    for (int y = 1; y <= h; y++) {
      for (int x = 1; x <= w; x++) {
        if ((x == 1 && y == 1) || (x == 1 && y == 2) || (x == 2 && y == 1)) {
          dp[1][1][0] = 1;
          dp[1][1][1] = 1;
          dp[1][1][2] = 1;
          dp[1][1][3] = 1;
          dp[2][1][0] = 1;
          dp[1][2][2] = 1;
        } else {
          dp[y][x][0] = dp[y - 1][x][0] % 100000 + dp[y - 1][x][1] % 100000;
          dp[y][x][1] = dp[y - 1][x][2] % 100000;
          dp[y][x][2] = dp[y][x - 1][2] % 100000 + dp[y][x - 1][3] % 100000;
          dp[y][x][3] = dp[y][x - 1][0] % 100000;
        }
      }
    }
    ans = dp[h][w][0] + dp[h][w][1] + dp[h][w][2] + dp[h][w][3];
    cout << ans % 100000 << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdio>
#include <cstdlib>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
  int h, w;
  while (cin >> w >> h) {
    if (w == 0 && h == 0)
      break;
    int dp[100][100][4] = {}, ans = 0;
    // 0　１つ前で曲がらずに下から来て
    // 1   曲がって下から
    // 2  １つ前で曲がらずに左から来る
    // 3   曲がって左から
    for (int y = 1; y <= h; y++) {
      for (int x = 1; x <= w; x++) {
        if ((x == 1 && y == 1) || (x == 1 && y == 2) || (x == 2 && y == 1)) {
          dp[1][1][0] = 1;
          dp[1][1][1] = 1;
          dp[1][1][2] = 1;
          dp[1][1][3] = 1;
          dp[2][1][0] = 1;
          dp[1][2][2] = 1;
        } else {
          dp[y][x][0] = dp[y - 1][x][0] + dp[y - 1][x][1];
          dp[y][x][1] = dp[y - 1][x][2];
          dp[y][x][2] = dp[y][x - 1][2] + dp[y][x - 1][3];
          dp[y][x][3] = dp[y][x - 1][0];
        }
      }
    }
    ans = dp[h][w][0] + dp[h][w][1] + dp[h][w][2] + dp[h][w][3];
    cout << ans % 100000 << endl;
  }
}
Problem p00470 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int w, h;

int dp[2][2][110][110];

int dfs(bool f, bool p = true, int x = 1, int y = 1) {
  if (x > w || y > h)
    return 0;
  if (x == w && y == h) {
    return 1;
  }

  int &ret = dp[f][p][x][y];
  if (ret != -1)
    return ret;

  ret = 0;
  if (p) {
    ret += dfs(true, f == true, x + 1, y) % 100000;
    ret += dfs(false, f == false, x, y + 1) % 100000;
  } else {
    ret = dfs(f, true, x + f, y + !f) % 100000;
  }

  return ret %= 100000;
}

int solve() {
  return (dfs(true, true, 2, 1) % 100000 + dfs(false, true, 1, 2) % 100000) %
         100000;
}

int main() {
  while (cin >> w >> h, w) {
    memset(dp, -1, sizeof(dp));
    cout << solve() << endl;
  }
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int w, h;
set<string> po;

void dfs(bool f, bool p = true, int x = 1, int y = 1, string debug = "") {
  if (x > w || y > h)
    return;
  if (x == w && y == h) {
    // cout << debug << endl;
    po.insert(debug);
    return;
  }

  int ret = 0;
  if (p) {
    dfs(true, f == true, x + 1, y, debug + "x");
    dfs(false, f == false, x, y + 1, debug + "y");
  } else {
    dfs(f, true, x + f, y + !f, debug + (f ? "x" : "y"));
  }

  return;
}

int main() {
  while (cin >> w >> h, w) {
    po.clear();
    dfs(true);
    dfs(false);
    cout << po.size() % 100000 << endl;
  }
}
Problem p00470 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, s, e) for (int i = int(s); i <= int(e); i++)
#define rep(i, n) for (int i = 0; i < int(n); i++)

#define mod 100000

int T[101][101][4];

int main() {

  while (1) {
    int h, w;
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;

    rep(i, h) T[i][0][0] = 1;
    rep(i, w) T[0][i][2] = 1;

    REP(i, 1, h - 1) {
      REP(j, 1, w - 1) {

        T[i][j][0] = (T[i - 1][j][0] + T[i - 1][j][1]) % mod;
        T[i][j][1] = T[i - 1][j][2] % mod;
        T[i][j][2] = (T[i][j - 1][2] + T[i][j - 1][3]) % mod;
        T[i][j][3] = T[i][j - 1][0] % mod;
      }
    }

    cout << (T[h - 1][w - 1][0] + T[h - 1][w - 1][1] + T[h - 1][w - 1][2] +
             T[h - 1][w - 1][3]) %
                mod
         << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, s, e) for (int i = int(s); i <= int(e); i++)
#define rep(i, n) for (int i = 0; i < int(n); i++)

#define mod 100000

int T[101][101][2];

int main() {

  while (1) {
    int h, w;
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;

    rep(i, w) {
      rep(j, h) {

        if (i == 0)
          T[i - 1][j][0] = 0;
        if (i - 2 < 0)
          T[i - 2][j][1] = 0;
        if (j == 0)
          T[i][j - 1][1] = 0;
        if (j - 2 < 0)
          T[i][j - 2][0] = 0;

        T[i][j][0] = (T[i - 1][j][0] + T[i - 2][j][1]) % mod;
        T[i][j][1] = (T[i][j - 1][1] + T[i][j - 2][0]) % mod;

        if (i == 1 && j == 0)
          T[i][j][0] = 1;
        if (i == 0 && j == 1)
          T[i][j][1] = 1;
      }
    }

    cout << (T[w - 1][h - 1][0] + T[w - 1][h - 1][1] + T[w - 2][h - 1][1] +
             T[w - 1][h - 2][0]) %
                mod
         << endl;
  }

  return 0;
}
Problem p00470 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
using namespace std;

int w, h;
int dp[100][100][2][2];

int main() {
  while (1) {
    scanf("%d %d", &w, &h);
    if (w == 0 && h == 0)
      break;
    for (int i = 1; i < w; i++) {
      dp[i][0][1][1] = 1;
    }
    for (int j = 1; j < h; j++) {
      dp[0][j][0][0] = 1;
    }
    for (int i = 1; i < w; i++) {
      for (int j = 1; j < h; j++) {
        dp[i][j][0][0] = (dp[i][j - 1][0][0] + dp[i][j - 1][0][1]) % 100000;
        dp[i][j][0][1] = dp[i][j - 1][1][1] % 100000;
        dp[i][j][1][0] = dp[i - 1][j][0][0] % 100000;
        dp[i][j][1][1] = (dp[i - 1][j][1][0] + dp[i - 1][j][1][1]) % 100000;
        ;
      }
    }
    int ans = 0;
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++) {
        ans += dp[w - 1][h - 1][i][j];
        ans %= 100000;
      }
    printf("%d\\n", ans);
/*	
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				printf("%d\\t", dp[j][i][0][0] + dp[j][i][0][1] + dp[j][i][1][0] + dp[j][i][1][1]);
			}
			printf("\\n");
		}
*/	}
return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;

int w, h;
int dp[100][100][2][2];

int main() {
  while (1) {
    scanf("%d %d", &w, &h);
    for (int i = 1; i < w; i++) {
      dp[i][0][1][1] = 1;
    }
    for (int j = 1; j < h; j++) {
      dp[0][j][0][0] = 1;
    }
    for (int i = 1; i < w; i++) {
      for (int j = 1; j < h; j++) {
        dp[i][j][0][0] = (dp[i][j - 1][0][0] + dp[i][j - 1][0][1]) % 100000;
        dp[i][j][0][1] = dp[i][j - 1][1][1] % 100000;
        dp[i][j][1][0] = dp[i - 1][j][0][0] % 100000;
        dp[i][j][1][1] = (dp[i - 1][j][1][0] + dp[i - 1][j][1][1]) % 100000;
        ;
      }
    }
    int ans = 0;
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++) {
        ans += dp[w - 1][h - 1][i][j];
        ans %= 100000;
      }
    printf("%d\\n", ans);
/*	
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				printf("%d\\t", dp[j][i][0][0] + dp[j][i][0][1] + dp[j][i][1][0] + dp[j][i][1][1]);
			}
			printf("\\n");
		}
*/	}
return 0;
}
Problem p00470 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>
using namespace std;

const int MOD = 100000;
int W, H;

enum DIR { EAST, NORTH, NONE };

int dp[100][100][3][2];

int solve(int x, int y, DIR d, bool turn) {
  // cerr << x << " " << y << " ";

  if (x == W - 1 && y == H - 1) {
    //	cerr << "OK" << endl;
    return 1;
  } else if (x >= W || y >= H) {
    //	cerr << endl;
    return 0;
  }
  // cerr << endl;

  if (dp[x][y][d][turn] >= 0)
    return dp[x][y][d][turn];

  int res = 0;

  if (turn) {
    if (d != NORTH)
      res += solve(x + 1, y, EAST, false);
    if (d != EAST)
      res += solve(x, y + 1, NORTH, false);
  } else {
    res += solve(x + 1, y, EAST, NORTH == d);
    res += solve(x, y + 1, NORTH, EAST == d);
  }
  return dp[x][y][d][turn] = res % MOD;
}

int main() {
  while (cin >> W >> H, W) {
    memset(dp, -1, sizeof(dp));
    cout << solve(0, 0, NONE, false) << endl;
  }
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;

const int MOD = 100000;
int W, H;

enum DIR { EAST, NORTH, NONE };

int solve(int x, int y, DIR d, bool turn) {
  // cerr << x << " " << y << " ";

  if (x == W - 1 && y == H - 1) {
    //	cerr << "OK" << endl;
    return 1;
  } else if (x >= W || y >= H) {
    //	cerr << endl;
    return 0;
  }
  // cerr << endl;

  int res = 0;

  if (turn) {
    if (d != NORTH)
      res += solve(x + 1, y, EAST, false);
    if (d != EAST)
      res += solve(x, y + 1, NORTH, false);
  } else {
    res += solve(x + 1, y, EAST, NORTH == d);
    res += solve(x, y + 1, NORTH, EAST == d);
  }
  return res % MOD;
}

int main() {
  while (cin >> W >> H, W) {
    cout << solve(0, 0, NONE, false) << endl;
  }
}
Problem p00470 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#define INF 100000000
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

static const double EPS = 1e-8;

int tx[] = {1, 0};
int ty[] = {0, 1};

ll dp[101][101][2][2];

ll dfs(int x, int y, int isturn, int dir, int w, int h, bool isf) {
  if (x == w - 1 && y == h - 1)
    return 1;

  ll res = 0;
  for (int i = 0; i < 2; i++) {
    int nextT;
    if (isturn && i != dir)
      continue;
    if (!isf && i != dir)
      nextT = 1;
    else
      nextT = 0;
    int dx = x + tx[i];
    int dy = y + ty[i];
    if (dy < 0 || dx < 0 || dy >= h || dx >= w)
      continue;
    // printf("x:%d y:%dn",dx,dy);
    if (dp[dy][dx][dir][i] == -1)
      res += (dp[dy][dx][dir][i] = dfs(dx, dy, nextT, i, w, h, false) % 100000);
    else
      res += dp[dy][dx][dir][i];
  }

  return res;
}
int main() {
  int w, h;
  while (~scanf("%d %d", &w, &h)) {
    if (w == h && h == 0)
      break;
    memset(dp, -1, sizeof(dp));
    printf("%lld\\n", dfs(0, 0, 0, 0, w, h, true) % 100000);
  }
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#define INF 100000000
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

static const double EPS = 1e-8;

int tx[] = {1, 0};
int ty[] = {0, 1};

int dfs(int x, int y, int isturn, int dir, int w, int h, bool isf) {
  if (x == w - 1 && y == h - 1)
    return 1;

  int res = 0;
  for (int i = 0; i < 2; i++) {
    int nextT;
    if (isturn && i != dir)
      continue;
    if (!isf && i != dir)
      nextT = 1;
    else
      nextT = 0;
    int dx = x + tx[i];
    int dy = y + ty[i];
    if (dy < 0 || dx < 0 || dy >= h || dx >= w)
      continue;
    // printf("x:%d y:%d\\n",dx,dy);
    res += dfs(dx, dy, nextT, i, w, h, false);
  }

  return res;
}
int main() {
  int w, h;
  while (~scanf("%d %d", &w, &h)) {
    if (w == h && h == 0)
      break;
    printf("%d\\n", dfs(0, 0, 0, 0, w, h, true) % 100000);
  }
}
Problem p00470 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

int main() {

  typedef long long ll;

  using namespace std;

  int w, h;
  while (cin >> w >> h && !(h == 0 && w == 0)) {
    // ツ催渉可づ景dx
    // 0:ツ前ツづ個マツスツづ凝按つェツづづつ「ツづ按つュツづ、ツ右ツづ可進ツづアツづつ「ツづゥ
    // 1:ツ前ツづ個マツスツづづ慊つェツづづつ「ツづ按つュツづ、ツ湘」ツづ可進ツづアツづつ「ツづゥ
    // 2:ツ前ツづ個マツスツづ右ツづ可凝按つェツづつス
    // 3:ツ前ツづ個マツスツづ湘」ツづ凝按つェツづつス
    ll dp[4][101][101];

    for (int j = 0; j < 4; j++)
      for (int i = 0; i < 101; i++)
        fill(dp[j][i], dp[j][i] + 101, 0);

    for (int j = 0; j < h; j++) {
      for (int k = 0; k < w; k++) {
        for (int i = 0; i < 4; i++) {
          if (j == 1 && k == 0) {
            if (i == 1)
              dp[i][j][k] = 1;
          } else if (j == 0 && k == 1) {
            if (i == 0)
              dp[i][j][k] = 1;
          } else {
            // ツ可コツつゥツづァ
            if (j - 1 >= 0) {
              if (i == 1) {
                dp[i][j][k] += dp[1][j - 1][k];
                dp[i][j][k] += dp[3][j - 1][k];
              } else if (i == 3)
                dp[i][j][k] += dp[0][j - 1][k];
            }
            // ツ債カツつゥツづァ
            if (k - 1 >= 0) {
              if (i == 0) {
                dp[i][j][k] += dp[0][j][k - 1];
                dp[i][j][k] += dp[2][j][k - 1];
              } else if (i == 2)
                dp[i][j][k] += dp[1][j][k - 1];
            }
          }
          dp[i][j][k] %= 100000;
        }
      }
    }
    ll sum = 0;
    for (int i = 0; i < 4; i++)
      sum += dp[i][h - 1][w - 1];
    cout << sum % 100000 << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

const int dy[] = {0, 1};
const int dx[] = {1, 0};

int h, w;
int cnt = 0;

// ÅãÌøÍOñÌ®ìðL^·é
void dfs(int x, int y, int prvy, int prvx, bool tern) {
  if (x == w - 1 && y == h - 1) {
    cnt = (cnt + 1) % 100000;
    return;
  }
  for (int i = 0; i < 2; i++) {
    int ny = y + dy[i];
    int nx = x + dx[i];
    if (ny >= 0 && nx >= 0 && ny < h && nx < w) {
      // QñA±ÅÜªÁÄ¢È¢ê
      if (tern) {
        if (prvy - ny == 0 || prvx - nx == 0)
          dfs(nx, ny, y, x, false);
      }
      // OñÈªÁÄ¢È¢ê
      else {
        // ¡ñÈªçÈ¢ê
        if (prvy - ny == 0 || prvx - nx == 0 || prvy == -1)
          dfs(nx, ny, y, x, false);
        else
          dfs(nx, ny, y, x, true);
      }
    }
  }
}

int main() {

  while (cin >> w >> h && !(w == 0 && h == 0)) {
    dfs(0, 0, -1, -1, false);
    cout << cnt << endl;
  }

  return 0;
}
Problem p00470 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define INF 100000005
#define MAX 100001
#define dmp make_pair
#define dpb push_back
#define P pair<int, int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int dp[101][101][2][2];
int main() {
  int w, h;
  while (1) {
    scanf("%d%d", &w, &h);
    if (!w)
      break;
    for (int i = 1; i <= w; i++) {
      for (int j = 1; j <= h; j++) {
        dp[i][j][0][0] = dp[i][j - 1][0][0] + dp[i][j - 1][1][0];
        dp[i][j][0][1] = dp[i - 1][j][0][1] + dp[i - 1][j][1][1];
        dp[i][j][1][0] = dp[i - 1][j][0][1];
        dp[i][j][1][1] = dp[i][j - 1][0][0];
        rep(x, 2) rep(y, 2) dp[i][j][x][y] = dp[i][j][x][y] % 100000;
        dp[1][2][0][0] = dp[2][1][0][1] = 1;
        dp[1][2][1][1] = dp[2][1][1][0] = 1;
      }
    }
    int ans = 0;
    rep(i, 2) ans += dp[w][h][0][i];
    printf("%d\\n", ans % 100000);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define INF 100000005
#define MAX 100001
#define dmp make_pair
#define dpb push_back
#define P pair<int, int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int dp[101][101][2][2];
int main() {
  int w, h;
  while (1) {
    scanf("%d%d", &w, &h);
    for (int i = 1; i <= w; i++) {
      for (int j = 1; j <= h; j++) {
        dp[i][j][0][0] = dp[i][j - 1][0][0] + dp[i][j - 1][1][0];
        dp[i][j][0][1] = dp[i - 1][j][0][1] + dp[i - 1][j][1][1];
        dp[i][j][1][0] = dp[i - 1][j][0][1];
        dp[i][j][1][1] = dp[i][j - 1][0][0];
        rep(x, 2) rep(y, 2) dp[i][j][x][y] = dp[i][j][x][y] % 100000;
        dp[1][2][0][0] = dp[2][1][0][1] = 1;
        dp[1][2][1][1] = dp[2][1][1][0] = 1;
      }
    }
    int ans = 0;
    rep(i, 2) ans += dp[w][h][0][i];
    printf("%d\\n", ans % 100000);
  }
  return 0;
}
Problem p00470 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>
using namespace std;
int dp[101][101][5], h, w;
int solve(int x, int y, int p);
int main() {
  while (cin >> w >> h && w || h) {
    memset(dp, 0, sizeof(dp));
    cout << solve(0, 0, 0) << endl;
  }
}
int solve(int x, int y, int p) {
  if (dp[x][y][p] != 0)
    return dp[x][y][p];
  if (x == h - 1 && y == w - 1)
    return 1;
  if (x >= h || y >= w)
    return 0;

  int c;
  switch (p) {
  case 0:
    c = solve(x + 1, y, 1) + solve(x, y + 1, 2);
    break;
  case 1:
    c = solve(x + 1, y, 1) + solve(x, y + 1, 4);
    break;
  case 2:
    c = solve(x, y + 1, 2) + solve(x + 1, y, 3);
    break;
  case 3:
    c = solve(x + 1, y, 1);
    break;
  case 4:
    c = solve(x, y + 1, 2);
    break;
  }
  return dp[x][y][p] = c % 100000;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
int dp[100][100][4], h, w;
int solve(int x, int y, int p);
int main() {
  while (cin >> w >> h && h || w) {
    memset(dp, 0, sizeof(dp));
    cout << solve(0, 0, 0) << endl;
  }
}
int solve(int x, int y, int p) {
  if (x == h - 1 && y == w - 1)
    return 1;
  if (x >= h || y >= h)
    return 0;
  if (dp[x][y][p] != 0)
    return dp[x][y][p];

  int c = 0;
  switch (p) {
  case 0:
    c = solve(x + 1, y, 1) + solve(x, y + 1, 2);
    break;
  case 1:
    c = solve(x + 1, y, 1) + solve(x, y + 1, 4);
    break;
  case 2:
    c = solve(x + 1, y, 3) + solve(x, y + 1, 2);
    break;
  case 3:
    c = solve(x + 1, y, 1);
    break;
  case 4:
    c = solve(x, y + 1, 2);
    break;
  }
  return dp[x][y][p] = c % 100000;
}