Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstring>
- using namespace std;
- int n;
- int A[1000005], next[1000005] = {-1};
- int B[2000010];
- int main()
- {
- int pos = -1;
- 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]);
- memcpy(B + n, B, sizeof(int)*n);
- for (int i = 0, j = -1; i < n; ){
- while (j > -1 && A[i] != A[j]) j = next[j];
- i++;
- j++;
- next[i] = j;
- }
- for (int i = 0, j = 0; i < 2*n; ){
- while (j > -1 && B[i] != A[j]) j = next[j];
- i++;
- j++;
- if (j == n){
- pos = 2*n - i;
- j = next[j];
- }
- }
- if (pos >= 0) printf("DA\n%d\n", pos);
- else printf("NE\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement