結果
問題 | No.5001 排他的論理和でランニング |
ユーザー |
![]() |
提出日時 | 2018-03-17 02:58:49 |
言語 | Java (openjdk 23) |
結果 |
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 / |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
ソースコード
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();}}