답안 #829611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
829611 2023-08-18T13:21:03 Z Blagoj Data Transfer (IOI19_transfer) C++17
100 / 100
154 ms 2496 KB
#include <bits/stdc++.h>
#include "transfer.h"
// #include "grader.cpp"

using namespace std;

vector<int> get_attachment(vector<int> source) {
	int n = source.size();
	vector<int> extra;
	for (int i = 0; i < (n == 63 ? 6 : 8); i++) {
		int sum = 0;
		for (int j = 1; j <= n; j++) {
			if (j & (1 << i)) {
				sum ^= source[j - 1];
			}
		}
		extra.push_back(sum);
	}
	int last = 0;
	for (auto x : extra) last ^= x;
	extra.push_back(last);
	return {extra};
}

vector<int> retrieve(vector<int> data) {
	vector<int> extra;
	for (int i = data.size() - 1; (i > 62 && i <= 70) || (i > 254 && i <= 300); i--) extra.push_back(data[i]);
	reverse(extra.begin(), extra.end());
	int Xor = 0;
	for (int i = 0; i < extra.size() - 1; i++) Xor ^= extra[i];
	int sz = extra.size();
	while (sz--) data.pop_back();
	if (Xor != extra.back()) return data;
	int num = 0;
	for (int i = 0; i < (data.size() == 63 ? 6 : 8); i++) {
		int sum = 0;
		for (int j = 1; j <= data.size(); j++) {
			if (j & (1 << i)) {
				sum ^= data[j - 1];
			}
		}
		num |= (1 << i) * sum;
	}
	int cur = 0;
	for (int i = 0; i < extra.size() - 1; i++) cur |= (1 << i) * extra[i];
	int pos = num ^ cur;
	if (pos != 0) data[pos - 1] = !data[pos - 1];
	return data;
}

Compilation message

transfer.cpp: In function 'std::vector<int> retrieve(std::vector<int>)':
transfer.cpp:30:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  for (int i = 0; i < extra.size() - 1; i++) Xor ^= extra[i];
      |                  ~~^~~~~~~~~~~~~~~~~~
transfer.cpp:37:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for (int j = 1; j <= data.size(); j++) {
      |                   ~~^~~~~~~~~~~~~~
transfer.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |  for (int i = 0; i < extra.size() - 1; i++) cur |= (1 << i) * extra[i];
      |                  ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 644 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 3 ms 652 KB Output is correct
4 Correct 4 ms 644 KB Output is correct
5 Correct 4 ms 756 KB Output is correct
6 Correct 3 ms 652 KB Output is correct
7 Correct 3 ms 652 KB Output is correct
8 Correct 3 ms 740 KB Output is correct
9 Correct 3 ms 736 KB Output is correct
10 Correct 3 ms 644 KB Output is correct
11 Correct 4 ms 644 KB Output is correct
12 Correct 3 ms 704 KB Output is correct
13 Correct 3 ms 716 KB Output is correct
14 Correct 3 ms 644 KB Output is correct
15 Correct 3 ms 652 KB Output is correct
16 Correct 4 ms 640 KB Output is correct
17 Correct 3 ms 644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 2484 KB Output is correct
2 Correct 132 ms 2468 KB Output is correct
3 Correct 131 ms 2496 KB Output is correct
4 Correct 138 ms 2460 KB Output is correct
5 Correct 138 ms 2496 KB Output is correct
6 Correct 127 ms 2488 KB Output is correct
7 Correct 132 ms 2488 KB Output is correct
8 Correct 130 ms 2440 KB Output is correct
9 Correct 130 ms 2448 KB Output is correct
10 Correct 127 ms 2448 KB Output is correct
11 Correct 128 ms 2448 KB Output is correct
12 Correct 132 ms 2452 KB Output is correct
13 Correct 127 ms 2492 KB Output is correct
14 Correct 154 ms 2436 KB Output is correct
15 Correct 152 ms 2496 KB Output is correct
16 Correct 129 ms 2448 KB Output is correct
17 Correct 129 ms 2496 KB Output is correct
18 Correct 139 ms 2488 KB Output is correct
19 Correct 129 ms 2452 KB Output is correct