Submission
Status:
PPPPPPPPPP
Score: 100
User: Whally
Problemset: ลำแสงเลเซอร์สะท้อน
Language: cpp
Time: 0.003 second
Submitted On: 2025-04-14 11:18:00
#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 ((xm < yn && ym > xn)) return true;}
return false;
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n,m, cnt = 1; cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> r[i];
for (int i = 1; i <= m; i++) cin >> b[i];
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
if (i&1 && j &1){if (check(r[i],r[i+1],b[j],b[j+1],1)) cnt++;}
else if (i&1){if (check(r[i],r[i+1],b[j],b[j+1],0)) cnt++;}
else if (j&1){if (check(r[i],r[i+1],b[j],b[j+1],0)) cnt++;}
else {if (check(r[i],r[i+1],b[j],b[j+1],1)) cnt++;}
}
}
cout << cnt;
return 0;
}