Cerinta completa

We call an quadruple of positive integers, , beautiful if the following condition is true:

Note: is the bitwise XOR operator.

Given , , , and , count the number of beautiful quadruples of the form where the following constraints hold:

When you count the number of beautiful quadruples, you should consider two quadruples as same if the following are true:

  • They contain same integers.
  • Number of times each integers occur in the quadruple is same.

For example and should be considered as same.

Input Format

A single line with four space-separated integers describing the respective values of , , , and .

Constraints

  • For of the maximum score,

Output Format

Print the number of beautiful quadruples.

Sample Input

1 2 3 4

Sample Output

11

Explanation

There are beautiful quadruples for this input:

Thus, we print as our output.

Note that is same as .


Limbajul de programare folosit: java8

Cod:

import java.io.*;
import java.util.*;

public class Solution {
    static class FastScanner {
        private final InputStream in;
        private final byte[] buffer = new byte[1 << 16];
        private int ptr = 0, len = 0;
        FastScanner(InputStream is) { in = is; }
        private int read() throws IOException {
            if (ptr >= len) {
                len = in.read(buffer);
                ptr = 0;
                if (len <= 0) return -1;
            }
            return buffer[ptr++];
        }
        int nextInt() throws IOException {
            int c;
            do { c = read(); } while (c <= ' ');
            int x = 0;
            while (c > ' ') {
                x = x * 10 + (c - '0');
                c = read();
            }
            return x;
        }
    }

    public static void main(String[] args) throws Exception {
        FastScanner fs = new FastScanner(System.in);
        int[] v = new int[4];
        for (int i = 0; i < 4; i++) v[i] = fs.nextInt();
        Arrays.sort(v);
        int A = v[0], B = v[1], C = v[2], D = v[3];

        int MAXX = 8192;
        int[] freq = new int[MAXX];
        long pairs = 0;
        long ans = 0;

        for (int y = 1; y <= C; y++) {
            if (y <= B) {
                int lim = Math.min(A, y);
                for (int w = 1; w <= lim; w++) {
                    freq[w ^ y]++;
                    pairs++;
                }
            }

            for (int z = y; z <= D; z++) {
                int x = y ^ z;
                ans += pairs - freq[x];
            }
        }

        System.out.print(ans);
    }
}

Scor obtinut: 1.0

Submission ID: 464610941

Link challenge: https://www.hackerrank.com/challenges/xor-quadruples/problem

Beautiful Quadruples