-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP2061.cpp
More file actions
55 lines (50 loc) · 1.05 KB
/
P2061.cpp
File metadata and controls
55 lines (50 loc) · 1.05 KB
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
#include <bits/stdc++.h>
using namespace std;
deque<int> q;
int n;
int ru[100],chu[100];
vector<int> ans;
int flag;
void dfs(int x){
if(flag) return;
if(!q.empty()){
ans.push_back(q.back());
if(ans.size() == n){
flag = 1;
for(int i=0;i<ans.size();i++){
if(ans[i]!=chu[i]){
flag = 0;
break;
}
}
}
if(flag) return;
q.pop_back();
dfs(x);
q.push_back(ans.back());
ans.pop_back();
}
if(x<n){
q.push_front(ru[x]);
dfs(x+1);
q.pop_front();
q.push_back(ru[x]);
dfs(x+1);
q.pop_back();
}
}
signed main(){
// ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
while(cin>>n){
flag = 0;
ans.clear(),q.clear();
for(int i = 0;i < n;i++)
cin>>ru[i];
for(int i = 0;i < n;i++)
cin>>chu[i];
dfs(0);
if(flag) cout<<"YES\n";
else cout<<"NO\n";
}
return 0;
}