#include #include #include using namespace std; const int MAXM = 1000; const int MAXN = 1000; const int MAXP = 1000; int m; int n; int p; int s[MAXM][MAXN]; int ris[MAXM][MAXN]; void printS() { for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cout << s[i][j] << " "; } cout << endl; } cout << endl; } void printRis() { for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cout << ris[i][j] << " "; } cout << endl; } cout << endl; } void spread(int x, int y, int i){ // cout << "spread di " << x << "," << y << "," << i << endl; if (x<0||x>m-1||y<0||y>n-1) { // cout << "indice " << x << "," << y << " fuori dai limiti!" << endl; // cout << m << " " << n << endl; return; } if (s[x][y]==1){ if (ris[x][y]==-1) { // cout << "pongo n=" << i << " e spread ai vicini" << endl; ris[x][y]=i; spread(x-1,y,i); spread(x+1,y,i); spread(x,y-1,i); spread(x,y+1,i); } else if (ris[x][y]==0 || ris[x][y]==i) { // cout << "ris=0 oppure ris=i" << endl; return; } else { // FUSIONE! // cout << "fuuu sioooo neeee!!" << endl; ris[x][y]=i; spread(x-1,y,i); spread(x+1,y,i); spread(x,y-1,i); spread(x,y+1,i); } } else { // cout << "pongo 0" << endl; ris[x][y]=0; } } int fx = 0; int fy = 0; int stop = 0; void setNextIndex() { while (!stop && ris[fx][fy]!=-1) { fy++; // cout << fy << endl; if (fy==n) { // cout << "vale n!"<confronto) countCrit++; // cout << "provo!" << endl; s[i][j]=1; } } } return countCrit; } int main() { ifstream in("input.txt"); ofstream out("output.txt"); in >> m; in >> n; in >> p; int x; int y; for (int i = 0; i < p; i++) { in >> x >> y; s[x-1][y-1]=1; } // printS(); // printRis(); out << solve() << endl; out << checkCrit() << endl; return 0; }