結果

問題 No.5001 排他的論理和でランニング
ユーザー uafr_csuafr_cs
提出日時 2018-03-17 02:58:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,128 ms / 1,500 ms
コード長 1,963 bytes
コンパイル時間 2,355 ms
実行使用メモリ 56,308 KB
スコア 52,424,319
最終ジャッジ日時 2020-03-12 19:57:43
ジャッジサーバーID
(参考情報)
judge6 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,087 ms
52,256 KB
testcase_01 AC 781 ms
52,644 KB
testcase_02 AC 811 ms
52,640 KB
testcase_03 AC 911 ms
52,352 KB
testcase_04 AC 1,128 ms
52,396 KB
testcase_05 AC 862 ms
52,504 KB
testcase_06 AC 921 ms
52,360 KB
testcase_07 AC 950 ms
54,216 KB
testcase_08 AC 1,086 ms
52,344 KB
testcase_09 AC 728 ms
51,144 KB
testcase_10 AC 836 ms
54,288 KB
testcase_11 AC 874 ms
52,152 KB
testcase_12 AC 800 ms
52,260 KB
testcase_13 AC 1,074 ms
52,324 KB
testcase_14 AC 958 ms
54,328 KB
testcase_15 AC 870 ms
52,388 KB
testcase_16 AC 787 ms
52,240 KB
testcase_17 AC 809 ms
52,556 KB
testcase_18 AC 945 ms
52,252 KB
testcase_19 AC 877 ms
52,332 KB
testcase_20 AC 829 ms
52,492 KB
testcase_21 AC 831 ms
52,556 KB
testcase_22 AC 751 ms
52,476 KB
testcase_23 AC 748 ms
50,168 KB
testcase_24 AC 824 ms
52,376 KB
testcase_25 AC 961 ms
52,312 KB
testcase_26 AC 937 ms
52,260 KB
testcase_27 AC 857 ms
54,392 KB
testcase_28 AC 983 ms
52,348 KB
testcase_29 AC 994 ms
52,252 KB
testcase_30 AC 780 ms
52,360 KB
testcase_31 AC 973 ms
52,264 KB
testcase_32 AC 832 ms
52,240 KB
testcase_33 AC 1,105 ms
54,256 KB
testcase_34 AC 1,124 ms
52,416 KB
testcase_35 AC 961 ms
56,308 KB
testcase_36 AC 1,066 ms
52,452 KB
testcase_37 AC 961 ms
52,196 KB
testcase_38 AC 828 ms
54,320 KB
testcase_39 AC 854 ms
52,632 KB
testcase_40 AC 903 ms
54,304 KB
testcase_41 AC 785 ms
52,284 KB
testcase_42 AC 875 ms
52,212 KB
testcase_43 AC 915 ms
52,412 KB
testcase_44 AC 1,033 ms
52,264 KB
testcase_45 AC 1,047 ms
52,244 KB
testcase_46 AC 1,009 ms
52,612 KB
testcase_47 AC 871 ms
52,644 KB
testcase_48 AC 829 ms
55,860 KB
testcase_49 AC 1,046 ms
52,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
	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];
		}
		
		for(int x = 0; x < 2000000; x++){
			final int x1 = (int)(Math.random() * N);
			
			int x2 = (int)(Math.random() * N);
			while(x1 == x2){ x2 = (int)(Math.random() * N); }
			
			int x3 = (int)(Math.random() * N);
			while(x1 == x3 || x2 == x3){ x3 = (int)(Math.random() * N); }
			
			int x4 = (int)(Math.random() * N);
			while(x1 == x4 || x2 == x4 || x3 == x4){ x4 = (int)(Math.random() * N); }
			
			int x5 = (int)(Math.random() * N);
			while(x1 == x5 || x2 == x5 || x3 == x5 || x4 == x5){ x5 = (int)(Math.random() * N); }
			
			int x6 = (int)(Math.random() * N);
			while(x1 == x6 || x2 == x6 || x3 == x6 || x4 == x6 || x5 == x6){ x6 = (int)(Math.random() * N); }
			
			int count = 0;
			count += used[x1] ? 1 : 0;
			count += used[x2] ? 1 : 0;
			count += used[x3] ? 1 : 0;
			count += used[x4] ? 1 : 0;
			count += used[x5] ? 1 : 0;
			count += used[x6] ? 1 : 0;
			if(count != 3){ continue; }
			
			final long next_max = max ^ array[x1] ^ array[x2] ^ array[x3] ^ array[x4] ^ array[x5] ^ array[x6];
			if(next_max > max){
				max = next_max;
				
				used[x1] = !used[x1];
				used[x2] = !used[x2];
				used[x3] = !used[x3];
				used[x4] = !used[x4];
				used[x5] = !used[x5];
				used[x6] = !used[x6];
			}
		}
		
		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