-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeppaAndSwerChat.cpp
More file actions
43 lines (40 loc) · 1020 Bytes
/
Copy pathBeppaAndSwerChat.cpp
File metadata and controls
43 lines (40 loc) · 1020 Bytes
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
// Codeforces Problem: 1776H - Beppa and SwerChat
// Link: https://codeforces.com/problemset/problem/1776/H
// Status: Accepted Language: C++
#include<iostream>
using namespace std;
int main () {
int t;
cin>>t;
while (t--) {
int n;
cin>>n;
int ans = 0, idx = n - 1;
int arr[n], arr2[n];
for (int i = 0; i < n; i++) {
cin>>arr[i];
}
for (int i = 0; i < n; i++) {
cin>>arr2[i];
}
bool flag = true;
for (int i = n - 1; i >= 0; i--) {
if (flag == false) {
break;
}
for (int j = n - 1; j >= 0; j--) {
if (arr2[i] == arr[j]) {
if (j > idx) {
flag = false;
ans = i + 1;
break;
}
idx = j;
break;
}
}
}
cout<<ans<<"\n";
}
return 0;
}