FINDABC-Editorial

While testing different test cases. I came to a very interesting conclusion that the index of the minimum element will always be 1 of the 3 numbers in 1 of the many different tuples. Then we can take 2 variables a and b. Where a will be (arr[0](the sum of the 2 elements) - (idx of the minimum element)) - n and b will be n. Since all the three numbers are bounded by n. We can then bruteforce to form an array with elements (idx^i) + (a^i) + (b^i) and compare it to our original array. We will increase a by 1 and decrease b by 1 and keep checking for the correct combination.

Some java code for understanding

    public static void main (String[] args) throws java.lang.Exception
	{
        FastReader sc = new FastReader();
		int t = sc.nextInt();
		while(t-->0){
		    int n = sc.nextInt();
		    int[] arr = sc.readIntArray(n+1);
		    int idx = indexOfSmallest(arr);
		    if(arr[idx] == 0){
		        out.println(idx + " " + idx + " " + idx);
		    }
		    else{
    		    int sum = arr[0];
    		    int x = sum - idx;
    		    int a = x - n;
        		int b = n;
        		if(a < 0){
        		    b = b + a;
        		    a = 0;
        		}
        		while(a<=b){
            	    int[] temp = tempArr(idx,a,b,n);
            		if(Arrays.equals(temp,arr)){
            		    out.println(idx + " " + a + " " + b);
            		    break;
            		}
                    a++;
                	b--;
        		}
		    }
		}
		out.close();
	}
    public static int indexOfSmallest(int[] array){
        if (array.length == 0)
            return -1;
    
        int index = 0;
        int min = array[index];
    
        for (int i = 1; i < array.length; i++){
            if (array[i] <= min){
            min = array[i];
            index = i;
            }
        }
        return index;
    }
    
    public static int[] tempArr(int a,int b,int c,int n){
        	int[] arr = new int[n+1];
		    for(int i = 0;i<=n;i++){
		        arr[i] = ((a^i) + (b^i) + (c^i));
		    }
		    return arr;
    }

at the end , you have written this approach produces one of the answers. what if there are multiple answers and you have given only one for that? I had a different approach and I dont think that is wrong.

Can someone explain the intuition and derivation of set - unset = \frac{f(0)-f(2^i)}{2^i}

Thank you very much, it worked!!! @anishray042

1 Like

how bitcount is calculated
somebody explain me whole solution