結果

問題 No.5001 排他的論理和でランニング
ユーザー 37zigen37zigen
提出日時 2018-03-25 18:03:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,111 ms / 1,500 ms
コード長 2,950 bytes
コンパイル時間 2,374 ms
実行使用メモリ 54,028 KB
スコア 24,513,786
最終ジャッジ日時 2020-03-12 20:56:26
ジャッジサーバーID
(参考情報)
judge9 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,066 ms
53,996 KB
testcase_01 AC 933 ms
44,836 KB
testcase_02 AC 981 ms
47,352 KB
testcase_03 AC 1,013 ms
47,376 KB
testcase_04 AC 1,045 ms
53,920 KB
testcase_05 AC 1,016 ms
49,300 KB
testcase_06 AC 998 ms
48,680 KB
testcase_07 AC 1,008 ms
46,956 KB
testcase_08 AC 1,111 ms
50,268 KB
testcase_09 AC 924 ms
45,040 KB
testcase_10 AC 1,013 ms
46,972 KB
testcase_11 AC 1,007 ms
47,036 KB
testcase_12 AC 945 ms
44,888 KB
testcase_13 AC 1,100 ms
50,056 KB
testcase_14 AC 1,032 ms
51,008 KB
testcase_15 AC 1,005 ms
46,984 KB
testcase_16 AC 961 ms
45,156 KB
testcase_17 AC 987 ms
48,920 KB
testcase_18 AC 1,036 ms
48,740 KB
testcase_19 AC 990 ms
46,964 KB
testcase_20 AC 991 ms
50,852 KB
testcase_21 AC 996 ms
47,216 KB
testcase_22 AC 926 ms
44,932 KB
testcase_23 AC 930 ms
44,984 KB
testcase_24 AC 941 ms
46,848 KB
testcase_25 AC 1,000 ms
47,088 KB
testcase_26 AC 973 ms
51,088 KB
testcase_27 AC 939 ms
45,044 KB
testcase_28 AC 1,021 ms
46,876 KB
testcase_29 AC 1,018 ms
47,048 KB
testcase_30 AC 962 ms
47,204 KB
testcase_31 AC 1,033 ms
47,044 KB
testcase_32 AC 994 ms
46,984 KB
testcase_33 AC 1,053 ms
50,348 KB
testcase_34 AC 1,110 ms
50,276 KB
testcase_35 AC 1,034 ms
46,968 KB
testcase_36 AC 1,046 ms
50,268 KB
testcase_37 AC 1,034 ms
47,248 KB
testcase_38 AC 985 ms
47,060 KB
testcase_39 AC 1,014 ms
47,112 KB
testcase_40 AC 1,008 ms
46,876 KB
testcase_41 AC 962 ms
48,916 KB
testcase_42 AC 1,016 ms
47,388 KB
testcase_43 AC 1,013 ms
47,028 KB
testcase_44 AC 1,015 ms
46,956 KB
testcase_45 AC 1,025 ms
52,360 KB
testcase_46 AC 999 ms
46,932 KB
testcase_47 AC 1,002 ms
47,160 KB
testcase_48 AC 999 ms
46,896 KB
testcase_49 AC 1,018 ms
54,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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[n + m];
		for (int i = 0; i < member.length; ++i)
			member[i] = i;
		int answer = 0;
		for (int i = 0; i < m; ++i) {
			answer ^= a[i];
		}
		for (int i = 0; i < 1e7; ++i) {
			int rnd1 = (int) (Math.random() * n) + m;
			int rnd2 = (int) (Math.random() * m);
			int tmp = answer ^ a[member[rnd2]] ^ a[member[rnd2]];
			if (tmp > answer) {
				member[rnd2] ^= member[rnd1];
				member[rnd1] ^= member[rnd2];
				member[rnd2] ^= member[rnd1];
				answer = tmp;
			}
		}
		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < m; ++i) {
			pw.print(a[member[i]] + (i == m - 1 ? "\n" : " "));
		}
		pw.close();
	}

	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