Problem:
通学経路
問題
太郎君の住んでいるJOI市は，南北方向にまっすぐに伸びる a 本の道路と，東西方向にまっすぐに伸びる b 本の道路により，碁盤の目の形に区分けされている．
南北方向の a 本の道路には，西から順に 1, 2, ... , a の番号が付けられている．また，東西方向の b 本の道路には，南から順に 1, 2, ... , b の番号が付けられている．西から i 番目の南北方向の道路と，南から j 番目の東西方向の道路が交わる交差点を (i, j) で表す．
太郎君は，交差点 (1, 1) の近くに住んでおり，交差点 (a, b) の近くのJOI高校に自転車で通っている．自転車は道路に沿ってのみ移動することができる．太郎君は，通学時間を短くするため，東または北にのみ向かって移動して通学している．
現在， JOI市では， n 個の交差点 (x
1
, y
1
), (x
2
, y
2
), ... , (x
n
, y
n
) で工事を行っている．太郎君は工事中の交差点を通ることができない．
太郎君が交差点 (1, 1) から交差点 (a, b) まで，工事中の交差点を避けながら，東または北にのみ向かって移動して通学する方法は何通りあるだろうか．太郎君の通学経路の個数 m を求めるプログラムを作成せよ．
入力
入力は複数のデータセットからなる．各データセットは以下の形式で与えられる．入力はゼロを２つ含む行で終了する．
1行目には，空白を区切りとして2個の整数 a, b が書かれている．これは，南北方向の道路の本数と，東西方向の道路の本数を表す． a, b は 1 ≤ a, b ≤ 16 をみたす．
2行目には, 工事中の交差点の個数を表す整数 n が書かれている． n は 1 ≤ n ≤ 40 をみたす．
続く n 行 (3行目から n+2 行目) には，工事中の交差点の位置が書かれている． i+2 行目には空白で区切られた整数 x
i
, y
i
が書かれており，交差点 (x
i
, y
i
) が工事中であることを表す． x
i
, y
i
は 1 ≤ x
i
, y
i
≤ 16 をみたす．
データセットの数は 5 を超えない．
出力
データセットごとに, 太郎君の通学経路の個数 m を1行に出力する．
入出力例
入力例
5 4
3
2 2
2 3
4 2
5 4
3
2 2
2 3
4 2
0 0
出力例
5
5
下図は a=5, b=4, n=3 で，工事中の交差点が (2,2), (2,3), (4,2) の場合を表している．
この場合，通学経路は m=5 通りある． 5通りの通学経路を全て図示すると，以下の通り．
上記問題文と自動審判に使われるデータは、
情報オリンピック日本委員会
が作成し公開している問題文と採点用テストデータです。

Submitted solutions:

code_snippet: #include <iostream>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int a,b,n,cnt=0;
vector<vector<bool>> grid(17,vector<bool>(17,false));
vector<vector<bool>> visited(17,vector<bool>(17,false));
const int dx[2]={1,0};
const int dy[2]={0,1};

void dfs(int x,int y){
  if (x==a && y==b){
    cnt += 1;
    return;
  }
  rep(i,2){
    int nx=x+dx[i];
    int ny=y+dy[i];
    if(1<=nx and nx<=a and 1<=ny and ny<=b){
      if(!visited[nx][ny] and !grid[nx][ny]){
        visited[nx][ny]=true;
        dfs(nx,ny);
        visited[nx][ny]=false;
      }
    }
  }
  visited[x][y]=false;
}
void solve(){
  while(1){
    cin >> a >> b >> n;
    if(a==0 && b==0) break;

    grid.assign(17,vector<bool>(17,false));
    visited.assign(17,vector<bool>(17,false));
    cnt=0;

    rep(i,n){
      int x,y;
      cin >> x >> y;
      grid[x][y]=true;
    }

    if(!grid[1][1]){
      visited[1][1]=true;
      dfs(1,1);
    }

    cout << cnt << endl;
  }
}
int main(){
  solve();
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3380
final_rank: 8

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));}

#define endl '\n'
#define Out(s) {cout << (s) << '\n';}
#define _onez(s) ((s)? 1 : 0)
#define onez(s) Out(_onez(s))
void YES(bool t = 1) { Out(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { Out(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { Out(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {}
  return 0;
}

int solve() {
  ll a, b, n, x, y;
  cin >> a >> b;
  if ((a == 0) and (b == 0)) return 1;
  cin >> n;
  vv(char, s, a+1, b+1, '.');
  rep(n) {
    cin >> x >> y;
    s[x][y] = '#';
  }
  queue<pi> Q;
  Q.push(mp(1, 1));
  ll ans = 0;
  while (!Q.empty()) {
    auto [x, y] = Q.front(); Q.pop();
    if ((x == a) and (y == b)) {
      ans++;
      continue;
    }
    static const vi dx{1, 0};
    static const vi dy{0, 1};
    rep(i, len(dx)) {
      ll nx = x + dx[i];
      ll ny = y + dy[i];
      if ((nx <= a) and (ny <= b) and (s[nx][ny] == '.')) {
        Q.push(mp(nx, ny));
      }
    }
  }
  Out(ans);
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 15732
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll,ll>;
using vp = vector<pl>;
#define rep(i,n) for(ll i=0;i<(ll)(n);++i)
#define reps(i,s,n) for(ll i=(s);i<(ll)(n);++i)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);++i)
template<typename T>inline bool chmax(T &a,T b){return a<b?a=b,true:false;}
template<typename T>inline bool chmin(T &a,T b){return a>b?a=b,true:false;}
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define be(v) (v).begin(),(v).end()
const long long INF = 1e18;
inline ll ipow(ll x,ll p){
	ll ret=x; rep1(i,p-1) ret*=x; return ret;
}
#ifdef DEBUG
#include <debug.hpp>
#endif

bool solve(){
#ifdef DEBUG
	cout << "--- Input ---" << endl;
#endif
	ll A,B;cin>>A>>B;
	if(A==0 && B==0)return false;
	ll N;cin>>N;
	set<pl> st;
	rep(n,N){
		ll x,y;cin>>x>>y;st.emplace(--x,--y);
	}
	auto mo=[&](pl p){
		vp ret;
		if(p.fi+1<A && st.count(pl{p.fi+1,p.se})==0)ret.eb(p.fi+1,p.se);
		if(p.se+1<B && st.count(pl{p.fi,p.se+1})==0)ret.eb(p.fi,p.se+1);
		return ret;
	};
#ifdef DEBUG
	cout<<N<<" "<<A<<" "<<B<<" "<<st;
	cout << "--- Logic ---" << endl;
#endif
	ll ans=0;
	queue<pl> qu;
	qu.emplace(0,0);
	while(!qu.empty()){
		pl p=qu.front();qu.pop();
#ifdef DEBUG
		cout<<p<<endl;
#endif
		for(auto m:mo(p)){
			if(m.fi==A-1 && m.se==B-1){
				++ans;
			}else{
				qu.push(m);
			}
		}
	}

#ifdef DEBUG
	cout << "--- Answer ---" << endl;
#endif
	cout<<ans<<endl;
	return true;
}
int main(){
	while(solve());
	return 0;
}
//cout << fixed << setprecision(9);
accuracy: 1
time_ms: 80
memory_kb: 15828
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;
int MAP[17][17];
int a,b;
int n;
int x,y;
int cnt;
int dy[2]={0,1},dx[2]={1,0};
void func(int y,int x);
int main(void){
	int i,j;
	while(1){
		cin>>a>>b;
		if(a==0&&b==0)	break;
		for(i=1;i<17;i++){
			for(j=1;j<17;j++){
				MAP[i][j]=0;
			}
		}
		cnt=0;
		cin>>n;
		for(i=0;i<n;i++){
			cin>>x>>y;
			MAP[y][x]=-1;
		}
		func(1,1);
		cout<<cnt<<endl;
	}
	return 0;
}
void func(int y,int x){
	int i,j;
	int xx,yy;
	//cout<<y<<" "<<x<<endl;
	if(x==a&&y==b){
		cnt++;
		//cout<<cnt<<endl;
	}
	else{
		for(i=0;i<2;i++){
			xx=x+dx[i];
			yy=y+dy[i];
			if(xx<=a&&yy<=b&&MAP[yy][xx]!=-1){
				//MAP[yy][xx]=-1;
				func(yy,xx);
				//MAP[yy][xx]=0;
			}
		}
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3100
final_rank: 7

code_snippet: #include <bits/stdc++.h>

using namespace std;

int A, B, N;
int MapData[17][17];
int Dx[2] = { 1,0 };
int Dy[2] = { 0,1 };

int solve(int curX,int curY) {
	int nextX, nextY, sum;

	if (curX == A && curY == B) {
		return 1;
	}
	if (curX > A || curY > B) {
		return 0;
	}

	sum = 0;
	for (int i = 0; i < 2; ++i) {
		nextX = curX + Dx[i];
		nextY = curY + Dy[i];
		if (MapData[nextY][nextX] == 1) {
			continue;
		}
		sum += solve(nextX, nextY);
	}
	return sum;
}

int main() {
	int x, y;

	while (cin >> A >> B, A) {
		memset(MapData, 0, sizeof(MapData));
		cin >> N;
		for (int i = 0; i < N; ++i) {
			cin >> x >> y;
			MapData[y][x] = 1;
		}
		cout << solve(1, 1) << endl;
	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3076
final_rank: 5

code_snippet: #include <bits/stdc++.h>

using namespace std;

int A, B, N, Total;
int MapData[17][17];
int Dx[2] = { 1,0 };
int Dy[2] = { 0,1 };

bool solve(int curX,int curY) {
	int nextX, nextY;

	if (curX == A && curY == B) {
		return true;
	}
	for (int i = 0; i < 2; ++i) {
		nextX = curX + Dx[i];
		nextY = curY + Dy[i];
		if (nextX < 1 || nextX > A || nextY < 1 || nextY > B) {
			continue;
		}
		if (MapData[nextY][nextX] == 1) {
			continue;
		}
		if (solve(nextX, nextY)) {
			++Total;
		}
	}
	return false;
}

int main() {
	int x, y;

	while (cin >> A >> B, A) {
		memset(MapData, 0, sizeof(MapData));
		cin >> N;
		for (int i = 0; i < N; ++i) {
			cin >> x >> y;
			MapData[y][x] = 1;
		}
		Total = 0;
		solve(1, 1);
		cout << Total << endl;
	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3056
final_rank: 4

code_snippet: #include <bits/stdc++.h>
static const int MAX = 16;
static const int dx[2] = {-1, 0};
static const int dy[2] = {0, 1};
int W, H, gx, gy;
int map[MAX][MAX];

int bfs() {
    int sx = H-1, sy = 0;
    int ans = 0;
    std::queue<std::pair<int, int> > q;
    q.push({sx, sy});
    while(!q.empty()) {
        std::pair<int, int> p = q.front(); q.pop();
        if (p.first == gx && p.second == gy) { ans++; continue; }
        for (int i = 0; i < 2; i++) {
            int nx = p.first+dx[i], ny = p.second+dy[i];
            if (nx >= 0 && nx < H && ny >= 0 && ny < W && map[nx][ny] != 1) {
                q.push({nx, ny});
            }
        }
    }
    return ans;
}

int main() {
    int N, px, py;
    for (; ;) {
        std::scanf("%d %d", &W, &H);
        if (W == 0 && H == 0) break;
        gx = 0, gy = W-1;
        std::memset(map, 0, sizeof (map));
        std::scanf("%d", &N);
        for (int i = 0; i < N; i++) {
            std::scanf("%d %d", &py, &px);
            map[H-px][py-1] = 1;
        }
        std::cout << bfs() << std::endl;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 9300
final_rank: 15

code_snippet: #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int a, b, n;
vector<vector<bool>> g;

int Dfs(int i, int j) {
  if (i > a || j > b)
    return 0;
  if (!g[i][j])
    return 0;
  if (i == a && j == b)
    return 1;
  int res = Dfs(i + 1, j) + Dfs(i, j + 1);
  return res;
}

int main() {
  while (true) {
    cin >> a >> b;
    if (a == 0 && b == 0)
      break;
    cin >> n;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; ++i)
      cin >> x[i] >> y[i];
    g.resize(a + 1, vector<bool>(b + 1, true));
    for (int i = 0; i < n; ++i)
      g[x[i]][y[i]] = false;
    cout << Dfs(1, 1) << endl;
    g.clear();
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3020
final_rank: 3

code_snippet: // JOI - Prelim  0515
// 通学経路
#include <bits/stdc++.h>

using namespace std;

using Int  = int_fast64_t;
using UInt = uint_fast64_t;

template <typename T>
using vec1 = vector<T>;

template <typename T>
using vec2 = vec1<vec1<T>>;

template <typename T>
vec2<T> InitVec2(size_t x, size_t y, const T& i = T())
{
    return vec2<T>(y, vec1<T>(x, i));
}

template <typename T>
T Get(const vec2<T>& v2, size_t x, size_t y)
{
    return v2[y][x];
}

template <typename T>
T& Ref(vec2<T>& v2, size_t x, size_t y)
{
    return v2[y][x];
}

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

const array<Int, 2> dx{1, 0};
const array<Int, 2> dy{0, 1};

UInt       A_ = 0;
UInt       B_ = 0;
vec2<char> vec2map_;
UInt       goal_count = 0;

void move(UInt x, UInt y)
{
    if (x == A_ - 1 && y == B_ - 1) {
        ++goal_count;
        return;
    }
    if (x >= A_ || y >= B_) {
        return;
    }
    if (!Get(vec2map_, x, y)) {
        return;
    }
    for (auto i = 0u; i < dx.size(); ++i) {
        const auto nx = x + dx[i];
        const auto ny = y + dy[i];
        move(nx, ny);
    }
}

bool sub()
{
    A_ = cin2var<UInt>();
    B_ = cin2var<UInt>();

    if (!A_ || !B_) return false;

    vec2map_ = InitVec2<char>(A_, B_, 1);

    const auto N(cin2var<UInt>());
    for (auto i = 0u; i < N; ++i) {
        const auto X(cin2var<UInt>() - 1);
        const auto Y(cin2var<UInt>() - 1);
        Ref(vec2map_, X, Y) = 0;
    }

    goal_count = 0;
    move(0, 0);
    cout << goal_count << endl;

    return true;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    while (sub());
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3080
final_rank: 6

code_snippet: #include<queue>
#include<cstdio>
#include<algorithm>
#include<string.h>

using namespace std;

#define F first
#define S second

bool used[20][20] = { 0 };
bool map[20][20] = { 0 };
int mx[] = { 1,0,-1,0 };
int my[] = { 0,1,0,-1 };
int a, b, n;

bool check(int i, int j) {
	if (i >= 0 && i <= a && j >= 0 && j <= b) return true;
	return false;
}

int main() {
	while (scanf("%d%d", &a, &b), a != 0 && b != 0) {
		scanf("%d", &n);
		memset(map, false, sizeof(map));
		for (int i = 0; i < n; i++) {
			int x, y;
			scanf("%d%d", &x, &y);
			map[x][y] = true;
		}
		memset(used, false, sizeof(used));
		queue<pair<int, int> > q;
		q.push(make_pair(1, 1));
		int ans = 0;
		while (!q.empty()) {
			pair<int, int> qf = q.front();
			used[qf.F][qf.S] = true;
			q.pop();
			if (qf.F == a && qf.S == b) {
				ans++;
				continue;
			}
			for (int i = 0; i < 4; i++) {
				int MX = mx[i], MY = my[i];
				if (!map[qf.F + MX][qf.S + MY] && !used[qf.F + MX][qf.S + MY] && check(qf.F + MX, qf.S + MY)) {
					q.push(make_pair(qf.F + MX, qf.S + MY));
					//printf("%d %d\n", qf.F, qf.S);
				}
			}
		}
		printf("%d\n", ans);
	}
}
accuracy: 1
time_ms: 30
memory_kb: 8844
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;
int MAP[17][17];
int a,b;
int n;
int x,y;
int cnt;
int dy[2]={0,1},dx[2]={1,0};
void func(int y,int x);
int main(void){
	int i,j;
	while(1){
		cin>>a>>b;
		if(a==0&&b==0)	break;
		for(i=1;i<17;i++){
			for(j=1;j<17;j++){
				MAP[i][j]=0;
			}
		}
		cnt=0;
		cin>>n;
		for(i=0;i<n;i++){
			cin>>x>>y;
			MAP[y][x]=-1;
		}
		/*for(i=1;i<=b;i++){
			for(j=1;j<=a;j++){
				cout<<MAP[i][j];
			}
			cout<<endl;
		}*/
		func(1,1);
		cout<<cnt<<endl;
	}
	return 0;
}
void func(int y,int x){
	int i,j;
	int xx,yy;
	//cout<<y<<" "<<x<<endl;
	if(x==a&&y==b){
		cnt++;
	}
	else{
		for(i=0;i<2;i++){
			xx=x+dx[i];
			yy=y+dy[i];
			if(xx<=a&&yy<=b&&MAP[yy][xx]!=-1){
				MAP[yy][xx]=-1;
				func(yy,xx);
				MAP[yy][xx]=0;
			}
		}
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3016
final_rank: 2

code_snippet: #include <cstdio>
#include <algorithm>

int a, b, n, map[17][17];

int search(int x, int y)
{
	if (x == 1 && y == 1)
	{
		map[1][1] = 1;
		return 1;
	}

	int left = 0, down = 0;
	if (map[y][x - 1] != -1)
	{
		left = search(x - 1, y);
	}
	if (map[y - 1][x] != -1)
	{
		down = search(x, y - 1);
	}
	map[y][x] = left + down;

	return map[y][x];
}

int main()
{
	while (true)
	{
		for (int i = 0; i <= b; ++i)
		{
			std::fill(map[i], map[i] + a + 1, 0);
		}

		scanf("%d %d", &a, &b);
		if (a == 0 || b == 0)
		{
			break;
		}
		scanf("%d", &n);
		for (int i = 0; i < n; ++i)
		{
			int x, y;
			scanf("%d %d", &x, &y);
			map[y][x] = -1;
		}

		std::fill(map[0], map[0] + a + 1, -1);
		for (int i = 0; i <= b; ++i)
		{
			map[i][0] = -1;
		}

		printf("%d\n", search(a, b));
	}
}
accuracy: 1
time_ms: 10
memory_kb: 2724
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
 
int A, B, N;
map<P, int> mp;
vector<vector<ll>> dp(20, vector<ll>(20, -1));

ll rec(int y = 0, int x = 0){
    
    auto itr = mp.find(make_pair(x, y));
    if(itr != mp.end()) return 0;
    if(y >= B || x >= A) return 0;
    if(y == B - 1 && x == A - 1) return 1;
    
    ll res = 0;
    res += rec(y + 1, x);
    res += rec(y, x + 1);
    
    return res;
}

int main(void){
    
    do{
        scanf("%d %d", &A, &B);
        if(A == 0 && B == 0) continue;
        scanf("%d", &N);
        for(int i = 0; i < N; ++i){
            int a, b; scanf("%d %d", &a, &b);
            --a, --b;
            mp[make_pair(a, b)] = 1;
        }
        cout << rec() << endl;
        mp.clear();
        for(int i = 0; i < B; ++i) for(int j = 0; j < A; ++j) dp[i][j] = -1;
    }while(A != 0 && B != 0);
    
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3200
final_rank: 9

code_snippet: //英雄(笑)装備
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<string.h>
#include<vector>
#include<stdio.h>
using namespace std;
int main() {
	while (1) {
		int a, b, i, j, n, mp[18][18] = { 0 }, x, y, m = 0;
		cin >> a >> b;
		if (a == 0 && b == 0) {
			return 0;
		}
		cin >> n;
		for (i = 1; i <= n; i++) {
			cin >> x >> y;
			mp[x][y] = 1;
		}
		for (j = 0; j <= a + 1; j++) {
			mp[j][0] = 1;
			mp[j][b + 1] = 1;
		}
		for (j = 0; j <= b + 1; j++) {
			mp[0][j] = 1;
			mp[a + 1][j] = 1;
		}
		queue<pair<int, int> > que;
		pair<int, int> out;
		out.first = 1;
		out.second = 1;
		que.push(out);
		while (!que.empty()) {
			out = que.front();
			que.pop();
			if (mp[out.first + 1][out.second] == 0) {
				out.first++;
				que.push(out);
				out.first--;
			}
			if (mp[out.first][out.second + 1] == 0) {
				out.second++;
				que.push(out);
				out.second--;
			}
			if (out.first == a&&out.second == b) {
				m++;
			}
		}
		printf("%d\n", m);
	}
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 9388
final_rank: 16

code_snippet: #include <iostream>
#include <vector>
#include <queue>

//幅優先探索
class Point{
private:
  int x;//x座標
  int y;//y座標
  int depth;//深さ

public:
  Point(int a,int b);
  int GetXpoint();
  int GetYpoint();
  int GetDepth();
  std::vector<Point> make_offspring(int x_limit,int y_limit,std::vector<Point> exception);

};

void search();

std::vector<Point> get_exception(int exception_num);//通行できない点を求める。

int get_root_num(int x_limit,int y_limit,std::vector<Point> exception);//通学経路の個数を求める。

bool judge_point(int depth1,int depth2);//深さでその点が目的地かどうかを判断する。

Point::Point(int a,int b){
  this->x= a;
  this->y=b;
  this->depth=a+b-2;
}

int Point::GetXpoint(){
  return this->x;
}

int Point::GetYpoint(){
  return this->y;
}

int Point::GetDepth(){
  return this->depth;
}

std::vector<Point> Point::make_offspring(int x_limit,int y_limit,std::vector<Point> exception){
  std::vector<Point> offsprings;
  if(x_limit>= (this->x+1)){
    Point tmp= Point(this->x+1,this->y);
    bool flag = true;
    for(Point tmp1:exception){
      if(tmp1.GetXpoint()==tmp.GetXpoint() &&tmp1.GetYpoint()==tmp.GetYpoint()){
        flag = false;
        break;
      }
    }
    if(flag == true){
      offsprings.push_back(tmp);
    }
  //  std::cout<<this->x<<","<<this->y<<" x  "<<tmp.GetXpoint()<<","<<tmp.GetYpoint();
  }

  if(y_limit>=(this->y+1)){
    Point tmp= Point(this->x,this->y+1);
    bool flag = true;
    for(Point tmp1: exception){
      if(tmp1.GetXpoint()==tmp.GetXpoint() &&tmp1.GetYpoint()==tmp.GetYpoint()){
        flag = false;
        break;
      }
    }
    if(flag == true){
      offsprings.push_back(tmp);
    }
  //  std::cout<<"  y  "<<tmp.GetXpoint()<<" "<<tmp.GetYpoint()<<std::endl;
  }

  return offsprings;
}

void search(){
  int x_limit,y_limit;//x座標,y座標の上限

  while(std::cin >> x_limit >> y_limit && x_limit!=0 && y_limit!=0){
    int exception_num;
    std::cin >> exception_num;
    std::vector<Point> exception = get_exception(exception_num);
    std::cout << get_root_num(x_limit,y_limit,exception)<<std::endl;
  }
}

std::vector<Point> get_exception(int exception_num){
  std::vector<Point> exception;
  for(int i = 0;i< exception_num;i++){
    int x,y;
    std::cin>>x>>y;
    Point tmp=Point(x,y);
    exception.push_back(tmp);
  }

  return exception;
}

int get_root_num(int x_limit,int y_limit,std::vector<Point> exception){
  std::queue<Point> que;
  int num=0;
  Point start = Point(1,1),end=Point(x_limit,y_limit);
  que.push(start);
  while(que.empty() != true){
    Point tmp = que.front();
    que.pop();
    if(judge_point(tmp.GetDepth(),end.GetDepth() ) ){
      //std::cout<<num+1<<" "<<tmp.GetXpoint()<<" "<<tmp.GetYpoint()<<std::endl;
      num ++ ;
    }else{
      std::vector<Point> offsprings = tmp.make_offspring(x_limit,y_limit,exception);
      if(!offsprings.empty()){
        for(Point tmp_child:offsprings){
          que.push(tmp_child);
        }
      }
    }
  }
  return num;
}

bool judge_point(int depth1,int depth2){
  if(depth1== depth2){
    return true;
  }
  return false;
}

int main(void){
  search();
  return 0;
}
accuracy: 1
time_ms: 450
memory_kb: 12144
final_rank: 20

code_snippet: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;


int main(){
  while(1){
    ll a,b,n;
    cin>>b>>a;
    if(a==0&&b==0) break;
    bool con[20][20];
    cin>>n;
    for(int i=0; i<=20; i++){
      for(int j=0; j<=20; j++){
        con[i][j]=false;
      }
    }
    for(int i=0; i<n; i++){
      int c,d;
      cin>>c>>d;
      con[c][d]=true;
    }
    
    
//    for(int i=a; i>=1; i--){
//      for(int j=1; j<=b; j++){
//        if(con[j][i]) cout<<'*';
//        else cout<<'.';
//      }
//      cout<<en
//    }
    
    ll ans=0;
    queue<P> michi;
    michi.push(mk(1,1));
    while(!michi.empty()){
      P p=michi.front(); michi.pop();
      for(int i=0; i<2; i++){
        int x=p.first+dx[i],y=p.second+dy[i];
        if(x==b&&y==a) ans++;
        if(!con[x][y]&&x<=b&&y<=a){
          michi.push(mk(x,y));
        }
      }
    }
    
    cout<<ans<<en
  }
  RE
}
accuracy: 1
time_ms: 30
memory_kb: 9168
final_rank: 17

code_snippet: #include <iostream>
using namespace std;
int fields[20][20],goal_y,goal_x;
int counter=0;
int recursive(int y,int x){
/*      for( int i=0 ; i<=goal_y ; i++ ){
                for( int j=0 ; j<=goal_x ; j++ ){
                        if( i==y && j==x )
                                cout << "#";
                        else cout << fields[i][j];
                }
                cout<< endl;
        }
        cout << endl;
*/
        if(fields[y+1][x]!=-1 and y<=goal_y )
                recursive(y+1,x);
        if(fields[y][x+1]!=-1 and x<=goal_x )
                recursive(y,x+1);
        if(y==goal_y && x==goal_x )
                counter++;
        return 0;
}
int main(){
        while(true){
                counter=0;
                int x,y,m;
                cin >> x >> y;
                if(x+y==0)      break;
                goal_y=y-1,goal_x=x-1;
                for( int i=0 ; i<y ; i++ )
                        for( int j=0 ; j<x ; j++ )
                                fields[i][j]=0;
                cin >> m;
                for( int i=0 ; i<m ; i++ ){
                        cin >> x >> y;
                        fields[y-1][x-1]=-1;
                }
                recursive(0,0);
                cout << counter << endl;
        }
        return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 2992
final_rank: 10

code_snippet: #include<iostream>
#include<stdlib.h>
#include<queue>
using namespace std;

int a,b,cnt;
int* p;

struct P {
  int x,y;
};

int main () {
  while(cin>>a>>b,a|b){
    cnt=0;
    int d[a*b]={};p=d;int k;cin>>k;
    for(int i=0;i<k;++i){
      int x,y;cin>>x>>y;x--;y--;
      d[x+y*a]=1;
    }
    queue<P> q;q.push((P){0,0});
    while(!q.empty()){
      P e=q.front();q.pop();int x=e.x,y=e.y;
      if(x==a-1&&y==b-1){cnt++;continue;}
      if(x<a-1&&p[(x+1)+y*a]==0)q.push((P){x+1,y});
      if(y<b-1&&p[x+(y+1)*a]==0)q.push((P){x,y+1});
    }
    cout<<cnt<<endl;
  }
}
accuracy: 1
time_ms: 20
memory_kb: 9288
final_rank: 14

code_snippet: #include<iostream>
#include<vector>
#include<queue>
#include<utility>

using namespace std;

bool cant[20][20];
int a,b,ans;

int main()
{
	while(cin >> a >> b,a)
	{
		for(int i = 0;i < 20;i++)for(int j = 0;j < 20;j++)
		{
			cant[i][j] = false;
		}
		
		ans = 0;
		int n;
		cin >> n;
		
		for(int i = 0;i < n;i++)
		{
			int x,y;
			cin >> x >> y;
			cant[x-1][y-1] = true;
		}
		
		queue<pair<int,int> > q;
		q.push(make_pair(0,0));
		
		while(!q.empty())
		{
			pair<int,int> tmp = q.front();q.pop();
			
			if(tmp.first == a-1 && tmp.second == b-1)
			{
				ans++;
				continue;
			}
			
			if(cant[tmp.first][tmp.second] == true)
			{
				continue;
			}
			
			if(tmp.first < a-1)
			{
				q.push(make_pair(tmp.first+1,tmp.second));
			}
			
			if(tmp.second < b-1)
			{
				q.push(make_pair(tmp.first,tmp.second+1));
			}
		}
		
		cout << ans << endl;
	}
		

	
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 9228
final_rank: 13

code_snippet: #include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;

int main(){
  int a,b;
  while(cin>>a>>b,a+b){
    int MAP[a+1][b+1]={};
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
      int x,y;
      cin>>x>>y;
      MAP[x][y]=1;
    }
    queue<pair<int,int> >que;
    que.push(mp(1,1));
    int ans=0;
    while(!que.empty()){
      pair<int,int>now=que.front();
      que.pop();
      if(now.F==b&&now.S==a){
	ans++;
	continue;
      }
      if(now.F+1>0&&now.F+1<=b&&!MAP[now.S][now.F+1]){
	que.push(mp(now.F+1,now.S));
      }
      if(now.S+1>0&&now.S+1<=a&&!MAP[now.S+1][now.F]){
	que.push(mp(now.F,now.S+1));
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 9148
final_rank: 12