Submission #308006

#TimeUsernameProblemLanguageResultExecution timeMemory
308006kimjg1119Data Transfer (IOI19_transfer)C++17
100 / 100
295 ms2800 KiB
#include "transfer.h"
#include <bits/stdc++.h>

using namespace std;

vector<int> get_attachment_sub1(vector<int> sc) {
	int a[10] = {};
	for (int i = 0; i < sc.size(); i++) {
		for (int j = 0; j < 6; j++)
			if(sc[i]) a[j] ^= (i + 1) & (1 << j);
	}
	vector<int> r;
	for (int i = 0; i < 6; i++)
		if (a[i]) r.push_back(1);
		else r.push_back(0);
	
	vector<int> at;
	for (int i = 0; i < 1; i++) {
		for (int j = 0; j < 6; j++)
			at.push_back(r[j]);
	}
	int s = 0;
	for (int i = 0; i < 6; i++) s += r[i];
	at.push_back(s % 2);
	return at;
}

vector<int> get_attachment_sub2(vector<int> sc) {
	int a[10] = {};
	for (int i = 0; i < sc.size(); i++) {
		for (int j = 0; j < 8; j++)
			if (sc[i]) a[j] ^= (i + 1) & (1 << j);
	}
	vector<int> r;
	for (int i = 0; i < 8; i++)
		if (a[i]) r.push_back(1);
		else r.push_back(0);

	vector<int> at;
	for (int i = 0; i < 1; i++) {
		for (int j = 0; j < 8; j++)
			at.push_back(r[j]);
	}
	int s = 0;
	for (int i = 0; i < 8; i++) s += r[i];
	at.push_back(s % 2);
	return at;
}

std::vector<int> get_attachment(std::vector<int> source) {
	if (source.size() == 63) return get_attachment_sub1(source);
	else return get_attachment_sub2(source);
}

vector<int> retrieve_sub1(vector<int> d) {
	vector<int> t1;
	for (int i = 0; i < 7; i++) t1.push_back(d[i+63]);
	for (int i = 0; i < 7; i++) d.pop_back();
	int p = t1.back(); t1.pop_back();

	bool flag = true; int ts = 0;
	for (int i = 0; i < 6; i++) ts += t1[i];
	if (ts % 2 != p) flag = false;

	if (flag) {
		int a[10] = {};
		for (int i = 0; i < d.size(); i++) {
			for (int j = 0; j < 6; j++)
				if (d[i]) a[j] ^= (i+1) & (1 << j);
		}
		int r = 0;
		for (int i = 0; i < 6; i++) a[i] ^= t1[i] * (1<<i);
		for (int i = 0; i < 6; i++)
			if (a[i]) r |= (1 << i);
		if (r > 0) d[r - 1] = 1 - d[r - 1];
		return d;
	}
	else return d;
}

vector<int> retrieve_sub2(vector<int> d) {
	vector<int> t1;
	for (int i = 0; i < 9; i++) t1.push_back(d[i + 255]);
	for (int i = 0; i < 9; i++) d.pop_back();
	int p = t1.back(); t1.pop_back();

	bool flag = true; int ts = 0;
	for (int i = 0; i < 8; i++) ts += t1[i];
	if (ts % 2 != p) flag = false;

	if (flag) {
		int a[10] = {};
		for (int i = 0; i < d.size(); i++) {
			for (int j = 0; j < 8; j++)
				if (d[i]) a[j] ^= (i + 1) & (1 << j);
		}
		int r = 0;
		for (int i = 0; i < 8; i++) a[i] ^= t1[i] * (1 << i);
		for (int i = 0; i < 8; i++)
			if (a[i]) r |= (1 << i);
		if (r > 0) d[r - 1] = 1 - d[r - 1];
		return d;
	}
	else return d;
}

std::vector<int> retrieve(std::vector<int> data) {
	if (data.size() < 255) return retrieve_sub1(data);
	else return retrieve_sub2(data);
}

Compilation message (stderr)

transfer.cpp: In function 'std::vector<int> get_attachment_sub1(std::vector<int>)':
transfer.cpp:8:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  for (int i = 0; i < sc.size(); i++) {
      |                  ~~^~~~~~~~~~~
transfer.cpp: In function 'std::vector<int> get_attachment_sub2(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 < sc.size(); i++) {
      |                  ~~^~~~~~~~~~~
transfer.cpp: In function 'std::vector<int> retrieve_sub1(std::vector<int>)':
transfer.cpp:67:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |   for (int i = 0; i < d.size(); i++) {
      |                   ~~^~~~~~~~~~
transfer.cpp: In function 'std::vector<int> retrieve_sub2(std::vector<int>)':
transfer.cpp:93:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |   for (int i = 0; i < d.size(); i++) {
      |                   ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...