QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#525187 | #1817. AND Permutation | RngBased# | WA | 0ms | 3628kb | C++20 | 1.5kb | 2024-08-20 14:16:45 | 2024-08-20 14:16:45 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
int n, arr[300015];
set<int> s[65];
map<int, int> ans;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++){
cin >> arr[i];
if (n % 2 == 1 && arr[i] == 0)
continue;
for (int j = 0; j < 60; j++){
if (arr[i] & (1LL << j))
s[j].insert(arr[i]);
}
}
for (int _ = 0; _ < n / 2; _++){
vector<int> ori;
for (int j = 0; j < 60; j++)
if (!s[j].empty())
ori.emplace_back(*(--s[j].end()));
int mx = 0, val = 0, test = 0, res = 0;
for (auto i : ori){
if (__builtin_popcountll(i) > mx)
mx = __builtin_popcountll(i), val = i;
}
test = ((1LL << 4) - 1) - val;
mx = 0;
for (int i : ori){
int tmp = (test & i);
if (__builtin_popcountll(tmp) > mx)
mx = __builtin_popcountll(tmp), res = tmp;
}
ans[val] = res;
ans[res] = val;
for (int j = 0; j < 60; j++){
if (val & (1LL << j))
s[j].erase(val);
if (res & (1LL << j))
s[j].erase(res);
}
}
for (int i = 1; i <= n; i++)
cout << ans[arr[i]] << "\n";
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
input:
6 0 1 4 5 2 6
output:
4 6 0 2 5 1
result:
ok OK!
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3608kb
input:
272 315 138 126 6 394 297 44 273 84 200 9 197 396 133 16 46 65 87 86 336 316 174 140 162 250 306 52 188 57 36 63 192 320 388 10 156 15 208 38 32 31 228 30 305 234 384 220 142 72 27 337 110 94 317 304 242 398 209 5 323 29 284 301 309 244 230 261 61 254 266 194 296 275 313 80 206 214 88 308 18 288 106...
output:
132 81 17 0 132 130 0 130 0 51 212 66 130 130 0 0 198 296 0 157 145 96 83 337 5 132 0 17 134 0 208 0 0 137 0 0 0 63 0 0 0 33 0 130 5 142 18 384 0 0 162 416 0 130 149 5 1 262 234 140 0 194 130 130 9 264 258 130 272 213 284 87 132 130 286 65 264 55 147 216 238 292 9 260 88 0 260 0 0 200 132 0 270 67 3...
result:
wrong answer Bit and of corresponding values not zero.