Cod sursa(job #1709840)

Utilizator utcn_roxanaalexfloUTCN ROXANA ALEX FLO utcn_roxanaalexflo Data 28 mai 2016 14:08:19
Problema Padure2 Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 1.38 kb
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <fstream>

using namespace std;

struct pairhash {
public:
	template <typename T, typename U>
	std::size_t operator()(const std::pair<T, U> &x) const
	{
		return std::hash<T>()(x.first) ^ std::hash<U>()(x.second);
	}
};


int previ[1000000];
int current[1000000];

int main()
{
	int N, M, C;
	
	map<pair<int, int>, bool> shrooms;

	ifstream inFile("padure2.in");
	ofstream outFile("padure2.out");

	inFile >> N >> M;

	inFile >> C;
	int a, b;
	
	for (int i = 0; i < C; i++){
		inFile >> a >> b;
		shrooms[make_pair(a - 1, b - 1)] = true;
	}

	previ[0] = 1;

	for (int i = 1; i < M; i++) {
		if (shrooms.find(make_pair(0, i)) != shrooms.end()) { // found shroom here
			previ[i] = 0;
		}
		else {			
			previ[i] = previ[i - 1];
		}
	}


	for (int i = 1; i < N; i++) {
		current[0] = previ[0];
		for (int j = 1; j < M; j++) {			
			if (shrooms.find(make_pair(i, j)) != shrooms.end()) { // found shroom here
				current[j] = 0;
			}
			else {
				current[j] = (current[j - 1] + previ[j]);
				while (current[j] >= 2000003)
					current[j] -= 2000003;
			}
		}
		
		for (int j = 0; j < M; j++) {
			previ[j] = current[j];
		}
	}

	outFile << current[M - 1];

	inFile.close();
	outFile.close();

    return 0;
}