Submission
Status:
PPPPPPPPPP
Score: 100
User: Whally
Problemset: ลำแสงเลเซอร์สะท้อน
Language: cpp
Time: 0.003 second
Submitted On: 2025-04-14 11:09:24
#include <bits/stdc++.h>
using namespace std;
int r[510], b[510];
bool check(int xn, int yn, int xm, int ym, int st)
{
if (st == 1){
if ((xm < xn && ym >= yn) || (xm > xn && ym <= yn)) return true;
}
else if (st == 2){
if ((xm < yn && ym > xn)) return true;
}
else if (st == 3){
if ((xm < yn && ym > xn)) return true;
}
else{
if ((xm < xn && ym >= yn) || (xm > xn && ym <= yn)) return true;
}
return false;
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n,m; cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> r[i];
for (int i = 1; i <= m; i++) cin >> b[i];
int cnt = 1;
for (int i = 0; i < n; i++){
if (i%2){
for (int j = 0; j < m; j++){
if (j%2){
if (check(r[i],r[i+1],b[j],b[j+1],1)){
cnt++;
}
}
else {
if (check(r[i],r[i+1],b[j],b[j+1],2)){
cnt++;
}
}
}
}
else {
for (int j = 0; j < m; j++){
if (j%2){
if (check(r[i],r[i+1],b[j],b[j+1],3)){
cnt++;
}
}
else {
if (check(r[i],r[i+1],b[j],b[j+1],4)){
cnt++;
}
}
}
}
}
cout << cnt;
return 0;
}