Pagini recente » Cod sursa (job #252564) | Cod sursa (job #1345740) | Cod sursa (job #203949) | Cod sursa (job #1731185) | Cod sursa (job #1709599)
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
using namespace std;
const int MOD = 2000003;
inline std::pair<int, int>& static_pair(int x, int y) {
static std::pair<int, int> result;
result.first = x;
result.second = y;
return result;
}
int main()
{
ifstream in("padure2.in");
ofstream out("padure2.out");
std::map< int, std::vector<int> > mushrooms;
int N, M, C;
in >> N >> M >> C;
for (int i = 0; i < C; ++i) {
int x, y;
in >> x >> y;
mushrooms[x].push_back(y);
}
std::vector<int> currentLine(M + 1000);
int firstMushroom;
if (mushrooms.count(1) > 0) {
std::vector<int> firstLine = mushrooms[1];
std::sort(firstLine.begin(), firstLine.end());
firstMushroom = firstLine[0];
}
for (int i = 1; i <= M; ++i) {
if (i == firstMushroom) {
break;
}
currentLine[i] = 1;
}
auto it = mushrooms.begin();
for (int ln = 2; ln <= N; ++ln) {
if (it != mushrooms.end() && ln == it->first) {
for (int i : it->second) {
currentLine[i] = -1;
}
it++;
}
for (int i = 1; i <= M; ++i) {
if (currentLine[i] != -1) {
currentLine[i] += currentLine[i - 1];
if (currentLine[i] >= MOD) {
currentLine[i] -= MOD;
}
}
else {
currentLine[i] = 0;
}
}
}
out << currentLine[M] << endl;
return 0;
}