結果
| 問題 |
No.5001 排他的論理和でランニング
|
| ユーザー |
FF256grhy
|
| 提出日時 | 2018-03-16 23:50:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.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 / |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 |
ソースコード
#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;
}
FF256grhy