Submission #3275010


Source Code Expand

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;

public class Main {
    InputStream is;

    int __t__ = 1;
    int __f__ = 0;
    int __FILE_DEBUG_FLAG__ = __f__;
    String __DEBUG_FILE_NAME__ = "src/D1";

    FastScanner in;
    PrintWriter out;

    int MOD = 1000000007;
    public void solve() {
        int N = in.nextInt();
        int[] a = in.nextIntArray(N);
        int[] cnt = new int[33];

        int xor = 0;
        for (int i = 0; i < N; i++) {
            int d = Integer.bitCount(a[i] ^ (a[i] - 1));
            cnt[d]++;
            xor ^= a[i];
        }

        int res = 0;
        for (int i = cnt.length - 1; i > 0; i--) {
            if ((xor & (1L << (i - 1))) != 0) {
                if (cnt[i] == 0) {
                    System.out.println(-1);
                    return;
                } else {
                    xor ^= (1L << i) - 1;
                    res++;
                }
            }
        }
        System.out.println(res);
    }

    long MULT(long x, long y) {
        return (x * y) % MOD;
    }

    long POW(long a, long p) {
        long res = 1;
        long val = a;
        while (p > 0) {
            if (p % 2 == 1) {
                res = MULT(res, val);
            }
            p >>= 1;
            val = MULT(val, val);
        }
        return res;
    }

    public void run() {
        if (__FILE_DEBUG_FLAG__ == __t__) {
            try {
                is = new FileInputStream(__DEBUG_FILE_NAME__);
            } catch (FileNotFoundException e) {
                // TODO 自動生成された catch ブロック
                e.printStackTrace();
            }
            System.out.println("FILE_INPUT!");
        } else {
            is = System.in;
        }
        in = new FastScanner(is);
        out = new PrintWriter(System.out);

        solve();
    }

    public static void main(final String[] args) {
        new Main().run();
    }

    class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastScanner(InputStream stream) {
            this.stream = stream;
            // stream = new FileInputStream(new File("dec.in"));

        }

        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++)
                array[i] = nextInt();

            return array;
        }

        int[][] nextIntMap(int n, int m) {
            int[][] map = new int[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextIntArray(m);
            }
            return map;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++)
                array[i] = nextLong();

            return array;
        }

        long[][] nextLongMap(int n, int m) {
            long[][] map = new long[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextLongArray(m);
            }
            return map;
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++)
                array[i] = nextDouble();

            return array;
        }

        double[][] nextDoubleMap(int n, int m) {
            double[][] map = new double[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = in.nextDoubleArray(m);
            }
            return map;
        }

        String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++)
                array[i] = next();

            return array;
        }

        String nextLine() {
            int c = read();
            while (isEndline(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        }
    }
}

Submission Info

Submission Time
Task C - Cheating Nim
User hiro116s
Language Java8 (OpenJDK 1.8.0)
Score 500
Code Size 5724 Byte
Status AC
Exec Time 160 ms
Memory 38736 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 26
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 70 ms 22356 KB
001.txt AC 68 ms 19412 KB
002.txt AC 137 ms 35256 KB
003.txt AC 120 ms 29976 KB
004.txt AC 128 ms 27608 KB
005.txt AC 119 ms 26516 KB
006.txt AC 136 ms 35988 KB
007.txt AC 159 ms 36020 KB
008.txt AC 137 ms 38736 KB
009.txt AC 137 ms 38616 KB
010.txt AC 135 ms 34840 KB
011.txt AC 137 ms 35160 KB
012.txt AC 134 ms 37520 KB
013.txt AC 135 ms 33808 KB
014.txt AC 138 ms 36756 KB
015.txt AC 137 ms 36756 KB
016.txt AC 135 ms 37432 KB
017.txt AC 134 ms 35732 KB
018.txt AC 160 ms 37620 KB
019.txt AC 141 ms 37328 KB
020.txt AC 136 ms 35640 KB
021.txt AC 92 ms 22484 KB
022.txt AC 99 ms 25388 KB
023.txt AC 144 ms 36072 KB
example0.txt AC 67 ms 18644 KB
example1.txt AC 68 ms 20564 KB