Submission #1835036


Source Code Expand

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


class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n=sc.nextInt();
        long[]a=new long[n];
        long x=0;
        int[]c=new int[31];
        for(int i=0;i<n;++i){
            a[i]=sc.nextLong();
            x^=a[i];
            c[Long.bitCount((a[i]&-a[i])-1)]++;
        }
        int ans=0;
        for(int i=30;i>=0;--i)
            if((x&1<<i)!=0)
                if(c[i]>0){
                    x^=(1<<(i+1))-1;
                    ans++;
                }else
                    break;
        out.println(x==0?ans:-1);
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Submission Info

Submission Time
Task C - Cheating Nim
User kirika_comp
Language Java8 (OpenJDK 1.8.0)
Score 500
Code Size 2032 Byte
Status AC
Exec Time 201 ms
Memory 38664 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 71 ms 18004 KB
001.txt AC 71 ms 17620 KB
002.txt AC 201 ms 34936 KB
003.txt AC 155 ms 32700 KB
004.txt AC 155 ms 30552 KB
005.txt AC 138 ms 26580 KB
006.txt AC 186 ms 36848 KB
007.txt AC 192 ms 36648 KB
008.txt AC 179 ms 34768 KB
009.txt AC 183 ms 35012 KB
010.txt AC 180 ms 38664 KB
011.txt AC 193 ms 36840 KB
012.txt AC 166 ms 33296 KB
013.txt AC 182 ms 33844 KB
014.txt AC 188 ms 34552 KB
015.txt AC 183 ms 33328 KB
016.txt AC 176 ms 36624 KB
017.txt AC 185 ms 33768 KB
018.txt AC 178 ms 36660 KB
019.txt AC 193 ms 35656 KB
020.txt AC 178 ms 34500 KB
021.txt AC 103 ms 20436 KB
022.txt AC 113 ms 22356 KB
023.txt AC 195 ms 36020 KB
example0.txt AC 72 ms 19156 KB
example1.txt AC 71 ms 19412 KB