結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー uafr_cs
提出日時 2015-05-11 21:56:20
言語 Java
(openjdk 23)
結果
AC  
実行時間 341 ms / 5,000 ms
コード長 1,861 bytes
コンパイル時間 2,178 ms
コンパイル使用メモリ 79,032 KB
実行使用メモリ 61,252 KB
最終ジャッジ日時 2024-07-04 11:44:32
合計ジャッジ時間 10,884 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		long[] inputs = new long[N];
		for(int i = 0; i < N; i++){
			inputs[i] = sc.nextLong();
		}
		
		final int SIZE = 64;
		long[] pivot = new long[SIZE + 1];
		for(int i = 0; i < N; i++){
			long value = inputs[i];
			
			for(int bit = SIZE; bit >= 0; bit--){
				if((value & (1l << bit)) == 0){
					continue;
				}
				
				if(pivot[bit] == 0){
					pivot[bit] = value;
					break;
				}else{
					value ^= pivot[bit];
				}
			}
		}
		
		int rank = SIZE + 1;
		for(int i = 0; i <= SIZE; i++){
			if(pivot[i] == 0){
				rank--;
			}
		}
		
		System.out.println(1l << rank);
	}
	
	public static class Scanner {
	    private BufferedReader br;
	    private StringTokenizer tok;

	    public Scanner(InputStream is) throws IOException {
	        br = new BufferedReader(new InputStreamReader(is));
	    }

	    private void getLine() throws IOException {
	        while (!hasNext()) { tok = new StringTokenizer(br.readLine()); }
	    }

	    private boolean hasNext() {
	        return tok != null && tok.hasMoreTokens();
	    }

	    public String next() throws IOException {
	        getLine(); return tok.nextToken();
	    }

	    public int nextInt() throws IOException {
	        return Integer.parseInt(next());
	    }
	    
	    public long nextLong() throws IOException {
	    	return Long.parseLong(next());
	    }
	    
	    public void close() throws IOException {
	        br.close();
	    }
	}
	
}
0