結果

問題 No.5001 排他的論理和でランニング
ユーザー FF256grhyFF256grhy
提出日時 2018-03-16 23:50:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 1,500 ms
コード長 2,576 bytes
コンパイル時間 1,389 ms
実行使用メモリ 7,424 KB
スコア 50,773,473
最終ジャッジ日時 2020-03-12 19:39:48
ジャッジサーバーID
(参考情報)
judge8 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
5,380 KB
testcase_01 AC 13 ms
5,376 KB
testcase_02 AC 17 ms
5,380 KB
testcase_03 AC 29 ms
5,376 KB
testcase_04 AC 53 ms
5,380 KB
testcase_05 AC 22 ms
5,376 KB
testcase_06 AC 34 ms
5,380 KB
testcase_07 AC 38 ms
5,376 KB
testcase_08 AC 48 ms
5,376 KB
testcase_09 AC 6 ms
5,380 KB
testcase_10 AC 20 ms
5,380 KB
testcase_11 AC 25 ms
5,380 KB
testcase_12 AC 20 ms
5,380 KB
testcase_13 AC 49 ms
5,376 KB
testcase_14 AC 33 ms
5,380 KB
testcase_15 AC 22 ms
5,376 KB
testcase_16 AC 13 ms
7,424 KB
testcase_17 AC 17 ms
5,380 KB
testcase_18 AC 32 ms
5,384 KB
testcase_19 AC 25 ms
5,376 KB
testcase_20 AC 19 ms
5,376 KB
testcase_21 AC 18 ms
5,376 KB
testcase_22 AC 10 ms
5,380 KB
testcase_23 AC 10 ms
5,376 KB
testcase_24 AC 23 ms
5,376 KB
testcase_25 AC 44 ms
5,380 KB
testcase_26 AC 39 ms
5,380 KB
testcase_27 AC 26 ms
5,376 KB
testcase_28 AC 38 ms
5,380 KB
testcase_29 AC 43 ms
5,384 KB
testcase_30 AC 13 ms
5,380 KB
testcase_31 AC 36 ms
5,376 KB
testcase_32 AC 19 ms
5,376 KB
testcase_33 AC 51 ms
5,376 KB
testcase_34 AC 54 ms
5,376 KB
testcase_35 AC 37 ms
5,380 KB
testcase_36 AC 49 ms
5,376 KB
testcase_37 AC 39 ms
5,376 KB
testcase_38 AC 19 ms
6,148 KB
testcase_39 AC 22 ms
5,376 KB
testcase_40 AC 28 ms
5,376 KB
testcase_41 AC 11 ms
5,376 KB
testcase_42 AC 26 ms
5,376 KB
testcase_43 AC 29 ms
5,376 KB
testcase_44 AC 45 ms
6,148 KB
testcase_45 AC 48 ms
5,380 KB
testcase_46 AC 47 ms
5,380 KB
testcase_47 AC 24 ms
5,380 KB
testcase_48 AC 19 ms
5,380 KB
testcase_49 AC 42 ms
5,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

#define bit(b, i) (((b) >> (i)) & 1)

int n, m, a[100000];
int B[16], C[16];

bool f[100000];
vector<int> ans;

int bc(int x) {
	int v = 0;
	while(x) { v += x % 2; x /= 2; }
	return v;
}

int main() {
	cin >> n >> m;
	inc(i, n) { cin >> a[i]; }
	
	inc(i, n) { B[a[i] >> 16]++; }
	
	auto ma = MP(-1, 0);
	inc(i, 1 << 16) {
		if(bc(i) % 2 != m % 2) { continue; }
		
		int x = 0, c = 0;
		inc(j, 16) {
			x ^= bit(i, j) * j;
			if(bit(i, j) && B[j] == 0) { c = -1e7; break; }
			c += (bit(i, j) ? (B[j] - 1) / 2 * 2 + 1 : B[j] / 2 * 2);
		}
		if(c >= m) { setmax(ma, MP(x, i)); }
	}
	int S = ma.SE;
	
	int r = m;
	inc(j, 16) { C[j] = bit(S, j); r -= C[j]; }
	assert(r >= 0);
	inc(j, 16) {
		while(r - 2 >= 0 && C[j] + 2 <= B[j]) { C[j] += 2; r -= 2; }
	}
	int sum = 0;
	inc(j, 16) { assert(C[j] <= B[j]); sum += C[j]; }
	assert(sum == m);
	
	inc(i, n) {
		if(C[a[i] >> 16] > 0) { f[i] = true; C[a[i] >> 16]--; }
	}
	
	inc(i, n) { if(f[i]) { ans.PB(a[i]); } }
	assert(ans.size() == m);
	inc(i, m) { cout << (i == 0 ? "" : " ") << ans[i]; }
	
	return 0;
}
0