結果

問題 No.5001 排他的論理和でランニング
ユーザー uafr_csuafr_cs
提出日時 2018-03-17 03:28:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,359 ms / 1,500 ms
コード長 1,989 bytes
コンパイル時間 2,287 ms
実行使用メモリ 59,940 KB
スコア 52,428,520
最終ジャッジ日時 2020-03-12 20:01:10
ジャッジサーバーID
(参考情報)
judge8 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,313 ms
52,332 KB
testcase_01 AC 961 ms
54,096 KB
testcase_02 AC 999 ms
52,260 KB
testcase_03 AC 1,123 ms
52,204 KB
testcase_04 AC 1,359 ms
52,304 KB
testcase_05 AC 1,053 ms
52,688 KB
testcase_06 AC 1,118 ms
52,480 KB
testcase_07 AC 1,163 ms
52,272 KB
testcase_08 AC 1,271 ms
52,540 KB
testcase_09 AC 901 ms
49,140 KB
testcase_10 AC 1,013 ms
52,336 KB
testcase_11 AC 1,081 ms
52,212 KB
testcase_12 AC 993 ms
52,632 KB
testcase_13 AC 1,303 ms
52,656 KB
testcase_14 AC 1,157 ms
53,920 KB
testcase_15 AC 1,057 ms
52,288 KB
testcase_16 AC 985 ms
52,284 KB
testcase_17 AC 1,017 ms
52,444 KB
testcase_18 AC 1,142 ms
54,180 KB
testcase_19 AC 1,064 ms
59,940 KB
testcase_20 AC 1,062 ms
52,428 KB
testcase_21 AC 1,007 ms
52,324 KB
testcase_22 AC 947 ms
54,512 KB
testcase_23 AC 945 ms
49,908 KB
testcase_24 AC 1,010 ms
52,372 KB
testcase_25 AC 1,173 ms
52,412 KB
testcase_26 AC 1,117 ms
52,524 KB
testcase_27 AC 1,036 ms
52,444 KB
testcase_28 AC 1,200 ms
54,600 KB
testcase_29 AC 1,237 ms
52,232 KB
testcase_30 AC 977 ms
52,392 KB
testcase_31 AC 1,170 ms
52,420 KB
testcase_32 AC 1,026 ms
52,236 KB
testcase_33 AC 1,328 ms
52,408 KB
testcase_34 AC 1,342 ms
54,316 KB
testcase_35 AC 1,194 ms
54,220 KB
testcase_36 AC 1,279 ms
52,160 KB
testcase_37 AC 1,174 ms
52,368 KB
testcase_38 AC 1,016 ms
52,688 KB
testcase_39 AC 1,040 ms
52,284 KB
testcase_40 AC 1,100 ms
52,248 KB
testcase_41 AC 969 ms
54,180 KB
testcase_42 AC 1,071 ms
55,912 KB
testcase_43 AC 1,129 ms
54,348 KB
testcase_44 AC 1,261 ms
55,880 KB
testcase_45 AC 1,298 ms
52,236 KB
testcase_46 AC 1,207 ms
52,248 KB
testcase_47 AC 1,068 ms
52,384 KB
testcase_48 AC 1,023 ms
52,404 KB
testcase_49 AC 1,239 ms
52,532 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++){
			int x = (int)(Math.random() * N);
			while(used[x]){ x = (int)(Math.random() * N); }
			
			used[x] = true;
			max ^= array[x];
		}
		
		for(int x = 0; x < 4000000; x++){
			final int x1 = (int)(Math.random() * N);
			final int x2 = (int)(Math.random() * N);
			final int x3 = (int)(Math.random() * N);
			final int x4 = (int)(Math.random() * N);
			//final int x5 = (int)(Math.random() * N);
			//final int x6 = (int)(Math.random() * N);
						
			int count = 0;
			count += used[x1] ? 1 : -1; used[x1] = !used[x1];
			count += used[x2] ? 1 : -1; used[x2] = !used[x2];
			count += used[x3] ? 1 : -1; used[x3] = !used[x3];
			count += used[x4] ? 1 : -1; used[x4] = !used[x4];
			//count += used[x5] ? 1 : -1; used[x5] = !used[x5];
			//count += used[x6] ? 1 : -1; used[x6] = !used[x6];
			if(count != 0){
				used[x1] = !used[x1];
				used[x2] = !used[x2];
				used[x3] = !used[x3];
				used[x4] = !used[x4];
				//used[x5] = !used[x5];
				//used[x6] = !used[x6];
				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;
			}else{
				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