-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathequivalent.cpp
More file actions
40 lines (32 loc) · 913 Bytes
/
equivalent.cpp
File metadata and controls
40 lines (32 loc) · 913 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
#include <bits/stdc++.h>
using namespace std;
int a[300005];
int b[300005];
bool check(int l1, int r1, int l2, int r2){
if( r1-l1 != r2-l2) return false;
if( l1 == r1 ){
return a[r1] == b[r2];
}
bool val = true;
for(int i = 0; i <= r1-l1 && val; ++i){
if(a[l1+i] != b[l2+i]) val = false;
}
if(val) return true;
bool v1 = check(l1, l1+(r1-l1)/2, l2, l2+(r2-l2)/2); //a1 to b1
bool v2 = check(l1+(r1-l1)/2+1, r1, l2+(r2-l2)/2+1, r2); //a2 to b2
bool j1 = check(l1, l1+(r1-l1)/2, l2+(r2-l2)/2+1, r2); //a1 to b2
bool j2 = check(l1+(r1-l1)/2+1, r1, l2, l2+(r2-l2)/2); // a2 to b1
if( (v1 && v2) || (j1 && j2) ) return true;
return false;
}
int main(){
int n;
scanf("%d", &n);
for(int i = 0; i < n; ++i){
scanf("%d", &a[i]);
}
for(int i = 0; i < n; ++i){
scanf("%d", &b[i]);
}
check(0, n-1, 0, n-1) ? printf("EQ\n") : printf("NEQ\n");
}