Submission #679314

# Submission time Handle Problem Language Result Execution time Memory
679314 2023-01-08T03:08:37 Z derek303 Data Transfer (IOI19_transfer) C++14
0 / 100
1 ms 852 KB
#include "transfer.h"

using namespace std;

vector<int> bin_converter(int N, int l) {
	vector<int> num;
	while (N > 0) {
		if (N % 2 == 0) {
			num.push_back(0);
		}
		else {
			num.push_back(1);
		}
		N = N / 2;
	}
	vector<int> leading_zeros;
	while (num.size() < l) {
		leading_zeros.push_back(0);
		l--;
	}
	for (int i = num.size()-1; i >= 0; i--) {
		leading_zeros.push_back(num[i]);
	}
	return leading_zeros;
}

vector<int> xor_gate(vector<int> a, vector<int> b) {
	vector<int> result;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == 0) {
			result.push_back(b[i]);
		}
		else if (b[i] == 0) {
			result.push_back(a[i]);
		}
		else {
			result.push_back(0);
		}
	}
	return result;
}

bool parity_check(vector<int> a, int p) {
	int counter = 0;
	for (auto i: a) {
		counter += i;
	}
	if (counter % 2 == p) {
		return true;
	}
	else {
		return false;
	}
}

std::vector<int> get_attachment(std::vector<int> source) {
	vector<int> pos;
	for (int i = 0; i < source.size(); i++) {
		if (source[i] == 1) {
			pos.push_back(i+1);
		}
	}
	int l = 6;
	if (source.size() == 255) {
		l = 8;
	}
	vector<vector<int>> bin_nums;
	for (auto i: pos) {
		bin_nums.push_back(bin_converter(i, l));
	}
	vector<int> k = bin_nums[0];
	for (int i = 1; i < bin_nums.size(); i++) {
		k = xor_gate(k, bin_nums[i]);
	}
	int counter = 0;
	for (auto i: k) {
		counter += i;
	}
	k.push_back(counter % 2);
	return k;
}

int int_to_bin(vector<int> bin) {
	int total = 0;
	int power = 1;
	for (int i = bin.size()-1; i >= 0; i--) {
		if (bin[i] == 1) {
			total += power;
		}
		power *= 2;
	}
	return total;
}

std::vector<int> retrieve(std::vector<int> data) {
	int l = 7;
	if (data.size() > 100) {
		l = 9;
	}
	vector<int> n, k;
	int p;
	for (int i = 0; i < data.size() - l; i++) {
		n.push_back(data[i]);
	}
	for (int i = data.size() - l; i < data.size()-1; i++) {
		k.push_back(data[i]);
	}
	p = data[data.size()-1];
	if (parity_check(k, p) == false) {
		return n;
	}

	vector<int> pos;
	for (int i = 0; i < data.size() - l; i++) {
		if (data[i] == 1) {
			pos.push_back(i+1);
		}
	}
	vector<vector<int>> bin_nums;
	for (auto i: pos) {
		bin_nums.push_back(bin_converter(i, l-1));
	}
	vector<int> new_k = bin_nums[0];
	for (int i = 1; i < bin_nums.size(); i++) {
		new_k = xor_gate(new_k, bin_nums[i]);
	}
	new_k = xor_gate(new_k, k);
	int index = int_to_bin(new_k);
	index--;
	if (index < 0) {
		return n;
	}
	n[index] = 1 - n[index];
	return n;
}

Compilation message

transfer.cpp: In function 'std::vector<int> bin_converter(int, int)':
transfer.cpp:17:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   17 |  while (num.size() < l) {
      |         ~~~~~~~~~~~^~~
transfer.cpp: In function 'std::vector<int> xor_gate(std::vector<int>, std::vector<int>)':
transfer.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for (int i = 0; i < a.size(); i++) {
      |                  ~~^~~~~~~~~~
transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:58:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for (int i = 0; i < source.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~
transfer.cpp:72:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |  for (int i = 1; i < bin_nums.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~~
transfer.cpp: In function 'std::vector<int> retrieve(std::vector<int>)':
transfer.cpp:102:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |  for (int i = 0; i < data.size() - l; i++) {
      |                  ~~^~~~~~~~~~~~~~~~~
transfer.cpp:105:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |  for (int i = data.size() - l; i < data.size()-1; i++) {
      |                                ~~^~~~~~~~~~~~~~~
transfer.cpp:114:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |  for (int i = 0; i < data.size() - l; i++) {
      |                  ~~^~~~~~~~~~~~~~~~~
transfer.cpp:124:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  124 |  for (int i = 1; i < bin_nums.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -