#include "transfer.h"
std::vector<int> get_attachment(std::vector<int> source)
{
unsigned const lgn = 32 - __builtin_clz(source.size());
std::vector<int> y(lgn + 1, 0);
int x = 0;
for (unsigned i = 1; i <= source.size(); i++)
{
y[0] ^= source[i - 1];
x ^= source[i - 1] * i;
}
for (unsigned i = 1; i <= lgn; i++)
y[i] = (x >> (lgn - i)) & 1;
return y;
}
std::vector<int> retrieve(std::vector<int> data)
{
unsigned const lgn = 31 - __builtin_clz(data.size());
unsigned const n = 1 << lgn;
int p = 0, x = 0;
for (unsigned i = 1; i <= n - 1; i++)
{
p ^= data[i - 1];
x ^= data[i - 1] * i;
}
if (p == data[n - 1])
return std::vector<int>(data.begin(), data.begin() + n - 1);
int y = 0;
for (unsigned i = 0; i < lgn; i++)
y = (y << 1) | data[n + i];
if (y != x)
data[(y ^ x) - 1] ^= 1;
return std::vector<int>(data.begin(), data.begin() + n - 1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
636 KB |
Output is correct |
2 |
Correct |
3 ms |
652 KB |
Output is correct |
3 |
Correct |
2 ms |
652 KB |
Output is correct |
4 |
Correct |
2 ms |
644 KB |
Output is correct |
5 |
Correct |
2 ms |
644 KB |
Output is correct |
6 |
Correct |
3 ms |
648 KB |
Output is correct |
7 |
Correct |
2 ms |
644 KB |
Output is correct |
8 |
Correct |
1 ms |
644 KB |
Output is correct |
9 |
Correct |
2 ms |
736 KB |
Output is correct |
10 |
Correct |
2 ms |
644 KB |
Output is correct |
11 |
Correct |
2 ms |
732 KB |
Output is correct |
12 |
Correct |
2 ms |
644 KB |
Output is correct |
13 |
Correct |
2 ms |
644 KB |
Output is correct |
14 |
Correct |
3 ms |
732 KB |
Output is correct |
15 |
Correct |
2 ms |
640 KB |
Output is correct |
16 |
Correct |
2 ms |
644 KB |
Output is correct |
17 |
Correct |
2 ms |
744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
2496 KB |
Output is correct |
2 |
Correct |
40 ms |
2496 KB |
Output is correct |
3 |
Correct |
39 ms |
2424 KB |
Output is correct |
4 |
Correct |
39 ms |
2488 KB |
Output is correct |
5 |
Correct |
40 ms |
2484 KB |
Output is correct |
6 |
Correct |
41 ms |
2504 KB |
Output is correct |
7 |
Correct |
40 ms |
2488 KB |
Output is correct |
8 |
Correct |
47 ms |
2492 KB |
Output is correct |
9 |
Correct |
43 ms |
2488 KB |
Output is correct |
10 |
Correct |
40 ms |
2496 KB |
Output is correct |
11 |
Correct |
52 ms |
2488 KB |
Output is correct |
12 |
Correct |
43 ms |
2488 KB |
Output is correct |
13 |
Correct |
41 ms |
2428 KB |
Output is correct |
14 |
Correct |
41 ms |
2488 KB |
Output is correct |
15 |
Correct |
41 ms |
2488 KB |
Output is correct |
16 |
Correct |
42 ms |
2472 KB |
Output is correct |
17 |
Correct |
45 ms |
2492 KB |
Output is correct |
18 |
Correct |
42 ms |
2488 KB |
Output is correct |
19 |
Correct |
44 ms |
2488 KB |
Output is correct |