結果

問題 No.5001 排他的論理和でランニング
ユーザー 37zigen37zigen
提出日時 2018-03-25 17:50:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,179 ms / 1,500 ms
コード長 3,245 bytes
コンパイル時間 2,410 ms
実行使用メモリ 54,344 KB
スコア 52,428,731
最終ジャッジ日時 2020-03-12 20:55:04
ジャッジサーバーID
(参考情報)
judge6 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,179 ms
50,148 KB
testcase_01 AC 959 ms
45,296 KB
testcase_02 AC 1,010 ms
47,144 KB
testcase_03 AC 1,082 ms
47,836 KB
testcase_04 AC 1,148 ms
50,420 KB
testcase_05 AC 1,018 ms
46,980 KB
testcase_06 AC 1,002 ms
47,044 KB
testcase_07 AC 1,022 ms
47,032 KB
testcase_08 AC 1,073 ms
50,148 KB
testcase_09 AC 944 ms
44,892 KB
testcase_10 AC 971 ms
46,864 KB
testcase_11 AC 1,005 ms
47,916 KB
testcase_12 AC 961 ms
45,084 KB
testcase_13 AC 1,088 ms
50,148 KB
testcase_14 AC 1,081 ms
48,072 KB
testcase_15 AC 1,054 ms
46,972 KB
testcase_16 AC 1,008 ms
46,976 KB
testcase_17 AC 991 ms
47,040 KB
testcase_18 AC 1,051 ms
47,668 KB
testcase_19 AC 1,001 ms
47,344 KB
testcase_20 AC 1,011 ms
50,872 KB
testcase_21 AC 1,015 ms
46,996 KB
testcase_22 AC 942 ms
44,904 KB
testcase_23 AC 964 ms
44,972 KB
testcase_24 AC 939 ms
44,900 KB
testcase_25 AC 992 ms
47,264 KB
testcase_26 AC 978 ms
47,052 KB
testcase_27 AC 973 ms
46,996 KB
testcase_28 AC 1,137 ms
48,084 KB
testcase_29 AC 1,049 ms
48,540 KB
testcase_30 AC 996 ms
46,892 KB
testcase_31 AC 1,090 ms
48,532 KB
testcase_32 AC 1,021 ms
52,788 KB
testcase_33 AC 1,110 ms
50,308 KB
testcase_34 AC 1,137 ms
54,344 KB
testcase_35 AC 1,106 ms
48,084 KB
testcase_36 AC 1,128 ms
50,348 KB
testcase_37 AC 1,037 ms
48,596 KB
testcase_38 AC 1,021 ms
47,036 KB
testcase_39 AC 1,019 ms
48,040 KB
testcase_40 AC 1,032 ms
46,956 KB
testcase_41 AC 986 ms
47,144 KB
testcase_42 AC 1,039 ms
47,980 KB
testcase_43 AC 1,040 ms
47,912 KB
testcase_44 AC 1,101 ms
48,112 KB
testcase_45 AC 1,089 ms
52,620 KB
testcase_46 AC 997 ms
47,356 KB
testcase_47 AC 1,041 ms
47,064 KB
testcase_48 AC 1,017 ms
46,988 KB
testcase_49 AC 1,083 ms
54,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextInt();
		}
		int[] member = new int[m];
		int answer = 0;
		boolean[] isMember = new boolean[n];
		for (int i = 0; i < m; ++i) {
			answer ^= a[i];
			member[i] = i;
			isMember[i] = true;

		}
		for (int i = 0; i < 1e7; ++i) {
			int rnd1 = (int) (Math.random() * m);
			int rnd2 = (int) (Math.random() * n);
			if (isMember[rnd2])
				continue;
			int tmp = answer ^ a[rnd2] ^ a[member[rnd1]];
			if (tmp > answer) {
				isMember[member[rnd1]] = false;
				isMember[rnd2] = true;
				member[rnd1] = rnd2;
				answer = tmp;
			}
		}
		for (int i = 0; i < m; ++i) {
			System.out.print(a[member[i]] + (i == m - 1 ? "\n" : " "));
		}
	}
	class Scanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        if (!hasNext()) throw new NoSuchElementException();
	        long n = 0;
	        boolean minus = false;
	        int b = readByte();
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        if (b < '0' || '9' < b) {
	            throw new NumberFormatException();
	        }
	        while(true){
	            if ('0' <= b && b <= '9') {
	                n *= 10;
	                n += b - '0';
	            }else if(b == -1 || !isPrintableChar(b)){
	                return minus ? -n : n;
	            }else{
	                throw new NumberFormatException();
	            }
	            b = readByte();
	        }
	    }
	    public int nextInt() {
	        long nl = nextLong();
	        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
	        return (int) nl;
	    }
	    public double nextDouble() { return Double.parseDouble(next());}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0