수직선과 수평선을 각각 따로 구한다음 한 칸마다 교차하는 점을 더해주었습니다
#include <iostream>
using namespace std;
#define MAX 103
int horizon[MAX][MAX];
int vertical[MAX][MAX];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
long long size, line;
cin >> size >> line;
for (int i = 1; i <= size; ++i) {
for (int j = 1; j <= size; ++j) {
horizon[i][j] = 0;
vertical[i][j] = 0;
}
}
for (int i = 0; i < line; ++i) {
int row, col;
char direct;
cin >> row >> col >> direct;
if (direct == 'R'){
for (int j = col; j <= size ; ++j) {
horizon[row][j]++;
}
}
else if(direct == 'L'){
for (int j = 1; j <= col ; ++j) {
horizon[row][j]++;
}
}
else if(direct == 'U'){
for (int j = 1; j <= row ; ++j) {
vertical[j][col]++;
}
}
else if(direct == 'D'){
for (int j = row; j <= size ; ++j) {
vertical[j][col]++;
}
}
}
long long sum =0;
for (int i = 1; i <= size; ++i) {
for (int j = 1; j <= size; ++j) {
sum += 1LL *horizon[i][j]*vertical[i][j];
}
}
cout<<sum;
}