Submission #1102230


Source Code Expand

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

public class Main
{
   public static void main(String[] args) throws Exception
   {
      PrintWriter out = new PrintWriter(System.out);
      new Main(new FastScanner(System.in), out);
      out.close();
   }

   public Main(FastScanner in, PrintWriter out)
   {
      int N = in.nextInt();
      
      int canTake = 0;
      int xor = 0;
      while (N-->0)
      {
         int v = in.nextInt();
         xor ^= v;
         canTake |= Integer.lowestOneBit(v);
      }
      
      int res = 0;
      while (xor > 0)
      {
         int pos = Integer.highestOneBit(xor);
         if ((pos&canTake) > 0)
         {
            xor ^= pos|(pos-1);
         }
         else
         {
            out.println(-1);
            return;
         }
         res++;
      }

      out.println(res);
   }
}

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

   public FastScanner(InputStream stream)
   {
      this.stream = stream;
   }

   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());
   }
   
   long nextLong()
   {
      return Long.parseLong(next());
   }

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

   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 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 tehqin
Language Java8 (OpenJDK 1.8.0)
Score 500
Code Size 2498 Byte
Status AC
Exec Time 179 ms
Memory 24032 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 97 ms 8016 KB
001.txt AC 95 ms 8148 KB
002.txt AC 172 ms 23320 KB
003.txt AC 159 ms 17068 KB
004.txt AC 160 ms 15928 KB
005.txt AC 146 ms 13980 KB
006.txt AC 171 ms 23352 KB
007.txt AC 171 ms 23344 KB
008.txt AC 169 ms 23056 KB
009.txt AC 172 ms 23476 KB
010.txt AC 174 ms 23240 KB
011.txt AC 170 ms 23352 KB
012.txt AC 171 ms 23356 KB
013.txt AC 170 ms 23344 KB
014.txt AC 172 ms 23224 KB
015.txt AC 172 ms 23356 KB
016.txt AC 172 ms 23348 KB
017.txt AC 170 ms 23480 KB
018.txt AC 172 ms 23344 KB
019.txt AC 174 ms 23224 KB
020.txt AC 179 ms 24032 KB
021.txt AC 130 ms 10192 KB
022.txt AC 132 ms 10192 KB
023.txt AC 171 ms 23476 KB
example0.txt AC 98 ms 8016 KB
example1.txt AC 97 ms 8020 KB