Submission #3274985


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 (cnt[i] == 0) {
                if ((xor & (1L << (i - 1))) == 0) {
                    continue;
                } else {
                    System.out.println(-1);
                    return;
                }
            }
            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 0
Code Size 5740 Byte
Status WA
Exec Time 138 ms
Memory 39444 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 11
WA × 15
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 19028 KB
001.txt AC 68 ms 21588 KB
002.txt WA 137 ms 37436 KB
003.txt WA 120 ms 30744 KB
004.txt AC 129 ms 29276 KB
005.txt AC 115 ms 23568 KB
006.txt WA 137 ms 36952 KB
007.txt WA 134 ms 37008 KB
008.txt WA 138 ms 39444 KB
009.txt WA 133 ms 37332 KB
010.txt WA 138 ms 37464 KB
011.txt WA 134 ms 35724 KB
012.txt WA 138 ms 37336 KB
013.txt WA 136 ms 36780 KB
014.txt WA 138 ms 37012 KB
015.txt WA 136 ms 35736 KB
016.txt WA 135 ms 36488 KB
017.txt AC 135 ms 33876 KB
018.txt WA 136 ms 33600 KB
019.txt WA 136 ms 38072 KB
020.txt AC 135 ms 35676 KB
021.txt AC 100 ms 24020 KB
022.txt AC 89 ms 21076 KB
023.txt AC 136 ms 34256 KB
example0.txt AC 70 ms 21076 KB
example1.txt AC 68 ms 23124 KB