QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#487060 | #2351. Lost in Transfer | clbzdq114514 | 0 | 2ms | 3464kb | C++20 | 1.6kb | 2024-07-22 15:43:00 | 2024-07-22 15:43:01 |
answer
#include <iostream>
#include <vector>
#include <algorithm>
#define pb push_back
using namespace std;
void transmit() {
int n;
cin >> n;
vector <int> a(n, 0);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
vector <int> ans;
int xsum = 0;
for (int i = 0; i < n; i++) {
xsum ^= a[i];
}
int l = 0, r = n - 1;
for (int i = 0; i < 8; i++) {
if (xsum >> i & 1) {
ans.pb(a[r--]), ans.pb(a[r--]);
}
else {
ans.pb(a[l++]), ans.pb(a[l++]);
}
}
if (xsum & 256) {
ans.pb(a[l++]);
}
else ans.pb(a[r--]);
for (int i = l; i <= r; i++) {
ans.pb(a[i]);
}
for (int i = 0; i < n; i++) {
cout << ans[i] << ' ';
}
cout << '\n';
}
void recover() {
int n;
cin >> n;
vector <int> a(n + 3, 0);
for (int i = 1; i <= n; i++) {
cin >> a[i];
cout << a[i] << ' ';
}
int xsum = 0;
for (int i = 1; i <= n; i++) {
xsum ^= a[i];
}
vector <int> ls(20, 0)/*, ans*/;
ls[0] = -1;
for (int i = 1; i <= 18; i++) {
ls[i] = a[i] > a[i + 1];
}
int cnt = 0, pos = 0;
for (int i = 1; i <= 18; i++) {
if (ls[i] ^ ls[i - 1]) {
if (cnt & 1) {
pos = i;
}
cnt = 1;
}
else {
cnt = 1 + cnt;
}
}
if (pos) {
for (int i = 17; i >= pos - 1; i--) {
ls[i + 1] = ls[i];
}
}
int ans = 0;
for (int i = 0; i <= 8; i++) {
if (ls[i << 1 | 1]) {
ans |= (1 << i);
}
}
if (ans ^ xsum) cout << (ans ^ xsum);
cout << '\n';
}
int main() {
ios::sync_with_stdio(0);
string s;
cin >> s;
int t;
cin >> t;
while (t--) {
if (s == "transmit") transmit();
else recover();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3464kb
input:
transmit 2 20 97 388 459 467 32 99 98 296 403 325 330 271 87 333 378 267 405 58 426 374 20 125 481 451 150 495 136 444 192 118 26 68 281 120 61 494 339 86 292 100 32
output:
467 459 426 405 403 388 378 374 333 330 325 296 271 267 32 58 99 87 97 98 495 494 26 32 481 451 444 339 61 68 292 281 86 100 118 120 192 125 136 150
input:
recover 2 19 467 459 426 405 403 388 378 374 333 330 325 296 271 267 32 58 99 87 97 19 495 494 26 32 451 444 339 61 68 292 281 86 100 118 120 192 125 136 150
output:
467 459 426 405 403 388 378 374 333 330 325 296 271 267 32 58 99 87 97 354 495 494 26 32 451 444 339 61 68 292 281 86 100 118 120 192 125 136 150 225
result:
wrong answer incorrect answer. (test case 1)