Advertisement
Saleh127

hackerearcth XOR of Subarray

Sep 29th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int find_subarray(long int a[],int n,int z);
  4. int main()
  5. {
  6. int t,i;
  7. scanf("%d",&t);
  8. for(i=0; i<t; i++)
  9. {
  10. int n,z,j;
  11. scanf("%d %d",&n,&z);
  12. long int a[10000];
  13. for(j=0; j<n; j++)
  14. scanf("%ld",&a[j]);
  15. int result=find_subarray(a,n,z);
  16. printf("%d\n",result);
  17. }
  18. return 0;
  19. }
  20. int find_subarray(long int a[],int n,int z)
  21. {
  22. int i,j,pos;
  23. long int min=10000000000002;
  24. long int sum;
  25. for(i=0; i<=n-z; i++)
  26. {
  27. sum=a[i];
  28. for(j=i+1; j<i+z; j++)
  29. sum=a[j]^sum;
  30. if(sum<=min)
  31. {
  32. min=sum;
  33. pos=i;
  34. }
  35. }
  36. return pos+1;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement