You are on page 1of 3

/*

AUTHOR : YASH SONI


!!! IT IS MY SOLUTION. IT IS NOT OFFICIAL. SO I CAN NOT GUARANTEE IF IT IS CORRE
CT OR NOT...
*/
#include <iostream>
using namespace std;
int main()
{
int N, M, w, b, ans = 0;
cin >> N >> M >> w >> b;
int graph[N][M] = {}, points[N][M] = {};
int x, y;
for (int i = 0; i < w; i++)
{
cin >> x >> y;
graph[x-1][y-1] = 1; // 1 denotes the presence of W
}
for (int i = 0; i < b; i++)
{
cin >> x >> y;
// 2 denotes the presence of B
graph[x-1][y-1] = 2;
}
// since those coordinates which are not input are unchanged, they are 0
. Here 0 denotes "."
/*
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
cout << graph[i][j] << " ";
coordinates
}
cout << endl;
}
*/

// Plotting of graph

for (int n = 0; n < N; n++) // i loop


{
for (int m = 0; m < M; m++) // j loop
{
if (graph[n][m] == 0) // if coordinate has a "."
{
int score = 1, initial = m, end; // tagging of t
he initial location of m
while (graph[n][m] == 0 && m < M)
{
score++; // increasing score for every "
." encountered
m++;
} // terminate when 1 or 2 occurs. Here 1 repres

ents W and 2 represents B


end = m; // tagging the end point as this point
is either a 1(W) or 2(B).
if (graph[n][m] == 1 && m < M) // continue once
again if 1(W) occurs.
{
do
{
score++;
m++;
} while (graph[n][m] == 0 && m < M);
}
if (m == M)
{
score--; // decreasing score if the boun
dary is reached as an extra point was alloted for the boundary at either of the
two loops.
}
for (int i = initial; i < end; i++) // alloting
scores to the corresponding points from the first W to the second W or B.
{
points[n][i] = score--; // storing the s
cores in another array. Can also be directly added (better one but not implement
ed for debugging).
//ans += score--;
}
// cout << score << endl;
m = end; // because after the first hinderence
, we need to check again for the next points.
}
}
}
/*
cout << endl;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
cout << points[i][j] << " ";
re for every location.
}
cout << endl;
}
*/
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
ans += points[i][j];
}
}
cout << ans;

// Printing the sco

return 0;
}

You might also like