結果

問題 No.5001 排他的論理和でランニング
ユーザー uafr_csuafr_cs
提出日時 2018-03-16 23:29:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 688 ms / 1,500 ms
コード長 1,147 bytes
コンパイル時間 2,316 ms
実行使用メモリ 58,004 KB
スコア 35,225,942
最終ジャッジ日時 2020-03-12 19:35:33
ジャッジサーバーID
(参考情報)
judge9 /
純コード判定しない問題か言語
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 637 ms
54,076 KB
testcase_01 AC 336 ms
52,428 KB
testcase_02 AC 372 ms
52,488 KB
testcase_03 AC 471 ms
54,632 KB
testcase_04 AC 678 ms
52,384 KB
testcase_05 AC 421 ms
52,320 KB
testcase_06 AC 489 ms
56,456 KB
testcase_07 AC 533 ms
54,400 KB
testcase_08 AC 660 ms
52,372 KB
testcase_09 AC 234 ms
49,140 KB
testcase_10 AC 402 ms
54,404 KB
testcase_11 AC 465 ms
57,884 KB
testcase_12 AC 371 ms
52,648 KB
testcase_13 AC 651 ms
58,004 KB
testcase_14 AC 514 ms
52,388 KB
testcase_15 AC 410 ms
54,524 KB
testcase_16 AC 343 ms
52,288 KB
testcase_17 AC 378 ms
55,912 KB
testcase_18 AC 507 ms
52,312 KB
testcase_19 AC 421 ms
54,484 KB
testcase_20 AC 389 ms
52,360 KB
testcase_21 AC 390 ms
54,436 KB
testcase_22 AC 316 ms
52,200 KB
testcase_23 AC 297 ms
49,936 KB
testcase_24 AC 402 ms
52,596 KB
testcase_25 AC 543 ms
52,288 KB
testcase_26 AC 497 ms
54,144 KB
testcase_27 AC 422 ms
52,260 KB
testcase_28 AC 533 ms
54,136 KB
testcase_29 AC 555 ms
52,192 KB
testcase_30 AC 333 ms
52,324 KB
testcase_31 AC 530 ms
52,492 KB
testcase_32 AC 392 ms
52,300 KB
testcase_33 AC 670 ms
52,296 KB
testcase_34 AC 688 ms
55,988 KB
testcase_35 AC 535 ms
52,348 KB
testcase_36 AC 622 ms
53,896 KB
testcase_37 AC 522 ms
52,272 KB
testcase_38 AC 384 ms
52,508 KB
testcase_39 AC 417 ms
52,284 KB
testcase_40 AC 453 ms
52,676 KB
testcase_41 AC 323 ms
54,200 KB
testcase_42 AC 443 ms
52,316 KB
testcase_43 AC 476 ms
54,400 KB
testcase_44 AC 575 ms
56,012 KB
testcase_45 AC 600 ms
52,364 KB
testcase_46 AC 560 ms
52,172 KB
testcase_47 AC 421 ms
52,308 KB
testcase_48 AC 390 ms
52,472 KB
testcase_49 AC 598 ms
52,136 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();
		
		int[] array = new int[N];
		for(int i = 0; i < N; i++){
			array[i] = sc.nextInt();
		}
		Arrays.sort(array);
		
		boolean[] used = new boolean[N];
		
		int count = 0;
		long xor = 0;
		for(int bit = 31; bit >= 0 && count < M; bit--){
			if(((1 << bit) & xor) != 0){ continue; }
			
			for(int i = 0; i < N; i++){
				if(used[i]){ continue; }
				if(((1 << bit) & array[i]) == 0){ continue; }
				
				used[i] = true;
				xor ^= array[i];
				count++;
				
				break;
			}
		}
		
		for(int i = 0; i < N && count < M; i++){
			if(used[i]){ continue; }
			
			used[i] = true;
			xor ^= array[i];
			count++;
		}
		//System.out.println(xor + " " + Arrays.toString(used));
		
		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