Submission #143837

# Submission time Handle Problem Language Result Execution time Memory
143837 2019-08-15T09:56:03 Z SpeedOfMagic Data Transfer (IOI19_transfer) C++17
100 / 100
161 ms 2652 KB
#include "transfer.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> get_attachment(vector<int> source) {
	int x = 0;
	vector<int> res;
	
	for (int i = 0; i < source.size(); i++)
		x ^= (i + 1) * source[i];
	
	int lim = (source.size() == 63) ? 6 : 8;
	int X = 0;
	for (int i = 0; i < lim; i++) {
		int d = (x & (1 << i)) != 0;
		res.push_back(d);
		X ^= d;
	}
	
	res.push_back(X);
	return res;
}

vector<int> retrieve(vector<int> data) {
	//for (int i = 0; i < data.size(); i++) cout << data[i]; cout << endl;
	int st;
	int len;
	if (data.size() == 70) {
		st = 63;
		len = 6;
	} else {
		st = 255;
		len = 8;
	}
	
	int x = 0;
	int X = 0;
	for (int i = st; i < st + len; i++) {
		x += (1 << (i - st)) * data[i];
		X ^= data[i];
	}
	
	int rx = 0;
	for (int i = 0; i < st; i++)
		rx ^= (i + 1) * data[i];
	
	vector<int> ans;
	if (x != rx) {
		if (X != data.back()) { //problem with xor
			for (int i = 0; i < st; i++)
				ans.push_back(data[i]);
		} else { //problem with the main part
			for (int i = 0; i < st; i++) {
				if ((rx ^ (i + 1)) == x)
					ans.push_back(1 - data[i]);
				else
					ans.push_back(data[i]);
			}
		}
	} else //problem with the last bit, or there's no problem
		for (int i = 0; i < st; i++)
			ans.push_back(data[i]);
	//for (int i : ans) cout << i; cout << endl;
	
	return ans;
}

Compilation message

transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:9:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < source.size(); i++)
                  ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 976 KB Output is correct
2 Correct 8 ms 1024 KB Output is correct
3 Correct 8 ms 1132 KB Output is correct
4 Correct 8 ms 1004 KB Output is correct
5 Correct 8 ms 1016 KB Output is correct
6 Correct 8 ms 1016 KB Output is correct
7 Correct 8 ms 1016 KB Output is correct
8 Correct 8 ms 888 KB Output is correct
9 Correct 8 ms 1016 KB Output is correct
10 Correct 8 ms 1144 KB Output is correct
11 Correct 8 ms 896 KB Output is correct
12 Correct 8 ms 1100 KB Output is correct
13 Correct 8 ms 972 KB Output is correct
14 Correct 9 ms 888 KB Output is correct
15 Correct 8 ms 976 KB Output is correct
16 Correct 8 ms 1028 KB Output is correct
17 Correct 8 ms 904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 2612 KB Output is correct
2 Correct 154 ms 2612 KB Output is correct
3 Correct 153 ms 2604 KB Output is correct
4 Correct 155 ms 2652 KB Output is correct
5 Correct 156 ms 2612 KB Output is correct
6 Correct 154 ms 2604 KB Output is correct
7 Correct 158 ms 2604 KB Output is correct
8 Correct 158 ms 2604 KB Output is correct
9 Correct 155 ms 2640 KB Output is correct
10 Correct 153 ms 2484 KB Output is correct
11 Correct 153 ms 2628 KB Output is correct
12 Correct 158 ms 2628 KB Output is correct
13 Correct 154 ms 2604 KB Output is correct
14 Correct 156 ms 2600 KB Output is correct
15 Correct 155 ms 2620 KB Output is correct
16 Correct 153 ms 2608 KB Output is correct
17 Correct 154 ms 2608 KB Output is correct
18 Correct 154 ms 2624 KB Output is correct
19 Correct 161 ms 2624 KB Output is correct