Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- using namespace std;
- #define MAX 1003
- int main()
- {
- int mat[MAX][MAX], east[MAX][MAX], south[MAX][MAX], west[MAX][MAX], north[MAX][MAX];
- int n, k, i, j, count = 0;
- cin >> n >> k;
- for(i=0; i<n; i++)
- for(j=0; j<n; j++)
- mat[i][j] = east[i][j] = south[i][j] = west[i][j] = north[i][j] = 0;
- for(i=0; i<k; i++){
- cin >> i >> j;
- mat[i][j] = 1;
- }
- //west
- for(i=0; i<n; i++){
- for(j=1; j<n; j++){
- west[i][j] = west[i][j-1] + mat[i][j-1];
- //north
- for(i=1; i<n; i++){
- for(j=0; j<n; j++){
- north[i][j] = north[i-1][j] + mat[i-1][j];
- //south
- for(i=n-2; i>=0; i--){
- for(j=0; j<n; j++){
- south[i][j] = south[i+1][j] + mat[i+1][j];
- //east
- for(i=0; i<n; i++){
- for(j=n-2; j>=0; j--)
- east[i][j] = east[i][j+1] + mat[i][j+1];
- for(i=0; i<n; i++){
- for(j=0; j<n; j++){
- if(mat[i][j] != 0 && west[i][j] > 0 && south[i][j] > 0 && north[i][j] > 0 && east[i][j] > 0)
- count++;
- }
- }
- cout << count << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement