Untitled

mail@pastecode.io avatar
unknown
java
8 days ago
1.5 kB
4
Indexable
Never
import java.util.*;

public class Solution {

    public static int get_ans(int N, List<Integer> P, List<Integer> A) {
        int maxGoodPathLength = 0;

        // Check each subarray for the condition
        for (int start = 0; start < N; start++) {
            int currentXor = 0;
            for (int end = start; end < N; end++) {
                currentXor ^= A.get(end);
                boolean isGoodPath = true;

                // Check if all elements in the subarray satisfy the condition
                for (int j = start; j <= end; j++) {
                    if (!(currentXor < A.get(j))) {
                        isGoodPath = false;
                        break;
                    }
                }

                if (isGoodPath) {
                    maxGoodPathLength = Math.max(maxGoodPathLength, end - start + 1);
                }
            }
        }

        return maxGoodPathLength;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int N = Integer.parseInt(scan.nextLine().trim());

        List<Integer> P = new ArrayList<>(N);
        for (int j = 0; j < N; j++) {
            P.add(Integer.parseInt(scan.nextLine().trim()));
        }

        List<Integer> A = new ArrayList<>(N);
        for (int j = 0; j < N; j++) {
            A.add(Integer.parseInt(scan.nextLine().trim()));
        }

        int result = get_ans(N, P, A);
        System.out.println(result);
    }
}
Leave a Comment