結果
問題 | No.5001 排他的論理和でランニング |
ユーザー | 37zigen |
提出日時 | 2018-03-25 18:18:22 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 811 ms / 1,500 ms |
コード長 | 3,149 bytes |
コンパイル時間 | 2,376 ms |
実行使用メモリ | 54,844 KB |
スコア | 52,428,750 |
最終ジャッジ日時 | 2020-03-12 20:57:23 |
ジャッジサーバーID (参考情報) |
judge8 / |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 795 ms
52,640 KB |
testcase_01 | AC | 664 ms
47,076 KB |
testcase_02 | AC | 687 ms
48,004 KB |
testcase_03 | AC | 742 ms
47,964 KB |
testcase_04 | AC | 801 ms
50,608 KB |
testcase_05 | AC | 701 ms
49,792 KB |
testcase_06 | AC | 731 ms
50,088 KB |
testcase_07 | AC | 742 ms
48,368 KB |
testcase_08 | AC | 753 ms
50,488 KB |
testcase_09 | AC | 624 ms
44,884 KB |
testcase_10 | AC | 709 ms
49,828 KB |
testcase_11 | AC | 720 ms
47,800 KB |
testcase_12 | AC | 690 ms
47,928 KB |
testcase_13 | AC | 750 ms
50,688 KB |
testcase_14 | AC | 761 ms
50,528 KB |
testcase_15 | AC | 700 ms
49,760 KB |
testcase_16 | AC | 682 ms
46,980 KB |
testcase_17 | AC | 692 ms
46,900 KB |
testcase_18 | AC | 757 ms
50,432 KB |
testcase_19 | AC | 716 ms
47,784 KB |
testcase_20 | AC | 718 ms
48,168 KB |
testcase_21 | AC | 700 ms
48,172 KB |
testcase_22 | AC | 664 ms
46,868 KB |
testcase_23 | AC | 662 ms
44,892 KB |
testcase_24 | AC | 674 ms
47,016 KB |
testcase_25 | AC | 738 ms
50,208 KB |
testcase_26 | AC | 722 ms
53,708 KB |
testcase_27 | AC | 710 ms
48,056 KB |
testcase_28 | AC | 752 ms
52,628 KB |
testcase_29 | AC | 756 ms
50,500 KB |
testcase_30 | AC | 684 ms
47,248 KB |
testcase_31 | AC | 754 ms
50,488 KB |
testcase_32 | AC | 713 ms
47,596 KB |
testcase_33 | AC | 811 ms
53,480 KB |
testcase_34 | AC | 805 ms
54,844 KB |
testcase_35 | AC | 747 ms
50,500 KB |
testcase_36 | AC | 744 ms
50,084 KB |
testcase_37 | AC | 767 ms
50,496 KB |
testcase_38 | AC | 701 ms
47,852 KB |
testcase_39 | AC | 710 ms
47,856 KB |
testcase_40 | AC | 740 ms
50,308 KB |
testcase_41 | AC | 677 ms
46,972 KB |
testcase_42 | AC | 734 ms
47,960 KB |
testcase_43 | AC | 731 ms
50,500 KB |
testcase_44 | AC | 775 ms
50,748 KB |
testcase_45 | AC | 774 ms
50,388 KB |
testcase_46 | AC | 725 ms
50,508 KB |
testcase_47 | AC | 710 ms
47,808 KB |
testcase_48 | AC | 700 ms
47,812 KB |
testcase_49 | AC | 787 ms
53,648 KB |
ソースコード
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.NoSuchElementException; import java.util.Random; 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]; } int cur = answer; int[] ans_arr = new int[n + m]; ans_arr = Arrays.copyOf(member, member.length); Random rnd = new Random(); for (int i = 0; i < 1e7; ++i) { int rnd1 = (int) (rnd.nextInt(n - m)) + m; int rnd2 = (int) (rnd.nextInt(m)); cur = cur ^ a[member[rnd1]] ^ a[member[rnd2]]; member[rnd2] ^= member[rnd1]; member[rnd1] ^= member[rnd2]; member[rnd2] ^= member[rnd1]; if (cur > answer) { answer = cur; ans_arr = Arrays.copyOf(member, member.length); } } PrintWriter pw = new PrintWriter(System.out); for (int i = 0; i < m; ++i) { pw.print(a[ans_arr[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)); } }