Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: anonymous
Problemset: เที่ยวเมืองวงกลม
Language: cpp
Time: 0.002 second
Submitted On: 2026-10-25 22:14:08
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
int a[n],b[n];
for(auto &i : a)cin >> i;
for(auto &i : b)cin >> i;
int x=1,y=1,cnt=0;
for(int i=0;i<n;i++){
int xx = a[i] ,yy = b[i];
int p = x, pp = xx,q = y, qq = yy;
if(p > pp) swap(p, pp);
if(q > qq) swap(q, qq);
if(p == q && pp == qq) cnt++;
else if(p != q && p != qq && pp != q && pp != qq){
if(p < q && pp > q && pp < qq) cnt++;
else if(q < p && qq > p && qq < pp) cnt++;
}
x = xx;
y = yy;
}
cout << cnt;
}