-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBalanced Tunnel.cpp
61 lines (44 loc) · 1.25 KB
/
Balanced Tunnel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
#define all(v) v.begin(),v.end()
#define loop(i, n) for (int (i) = 0; (i)<(n); (i)++)
#define loop2(i, a, b) for(int i = a; i <= b; i++)
#define pb push_back
#define test int t; cin>> t; while(t--)
const int N = 1e5 + 7;
const int bigN = 1e9 + 5;
ll mod = 1e9 + 7;
ll arr[N], temp[N], arr1[N];
int matrix[100][100], matrix2[100][100], matrix3[100][100];
bool boolArr[N];
void init() {
cin.tie(0);
cin.sync_with_stdio(0);
}
int main() {
init();
int n, carId, fined = 0, pos = 0, exitPos = 0;
vi enteredCars, exitCars;
vector<bool> finedCars(n + 1);
cin >> n;
loop(i, n)cin >> carId, enteredCars.push_back(carId);
loop(i, n)cin >> carId, exitCars.push_back(carId);
while (pos != n - 1) {
if (enteredCars[pos] == exitCars[exitPos]) {
pos++;
exitPos++;
} else if (finedCars[enteredCars[pos]]) pos++;
else fined++, finedCars[exitCars[exitPos]] = true, exitPos++;
}
cout << fined;
return 0;
}