結果

問題 No.5001 排他的論理和でランニング
ユーザー uafr_cs
提出日時 2018-03-16 23:06:31
言語 Java
(openjdk 23)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,562 bytes
コンパイル時間 2,191 ms
実行使用メモリ 54,324 KB
スコア 1,975,955
最終ジャッジ日時 2020-03-12 19:31:48
ジャッジサーバーID
(参考情報)
judge7 /
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 2 TLE * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	public static long random = 2463534242L;
	public static long random() {
		random ^= (random << 21);
		random ^= (random >>> 35);
		random ^= (random << 4);
		return random;
	}
		
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int M = sc.nextInt();
		
		long[] array = new long[N];
		for(int i = 0; i < N; i++){
			array[i] = sc.nextLong();
		}
		Arrays.sort(array);
		
		boolean[] used = new boolean[N];
		long max = 0;
		for(int i = 0; i < M; i++){
			used[(N - 1) - i] = true;
			max ^= array[(N - 1) - i];
		}
		
		double startTemp = 100;
		double endTemp = 10;
		
		final int LIMIT = 20000000;
		for(int x = 0; x < LIMIT; x++){
			final int fst = (N + (int)(random() % N)) % N;
			final int snd = (N + (int)(random() % N)) % N;
			if(used[fst] && used[snd]){ continue; }
			if(!used[fst] && !used[snd]){ continue; }
			
			final long next_max = max ^ array[fst] ^ array[snd];
			
			//double temp = startTemp + (endTemp - startTemp) * x / LIMIT;
			boolean force_next = (100 * (LIMIT - x)) > (LIMIT * (Math.abs(random()) % 100));
			
			if(next_max > max || force_next){
				max = next_max;
				used[fst] = !used[fst];
				used[snd] = !used[snd];
			}
		}
		
		boolean first = true;
		for(int i = 0; i < N; i++){	
			if(!used[i]){ continue; }
			
			System.out.print((first ? "" : " ") + (array[i]));
			first = false;
		}
		System.out.println();
	}
}
0