Submission #864606

# Submission time Handle Problem Language Result Execution time Memory
864606 2023-10-23T10:19:15 Z ThylOne Data Transfer (IOI19_transfer) C++14
100 / 100
44 ms 2596 KB
#include "transfer.h"
#include<bits/stdc++.h>

using namespace std;


std::vector<int> get_attachment(std::vector<int> source) {
	int lenCode = 7;
	if(source.size()!=63){
		lenCode = 9;
	}
	int xorIndex=0;
	int xor0;
	for(int i=1;i<=source.size();i++){
		if(source[i-1]){
			xorIndex^=i;
		}
		
	}
	
	vector<int> bits(lenCode);
	int sum=0;
	for(int i=0;i<lenCode-1;i++){
		bits[i]=(xorIndex>>i)&1;
		sum+=bits[i];
	}
	bits[lenCode-1]=sum&1;
	return bits;
}

std::vector<int> retrieve(std::vector<int> data) {
	int lenCode=9;
	if(data.size()==63+7){
		lenCode=7;
	}
	int len = data.size()-lenCode;
	int xorIndex=0;
	
	for(int i=1;i<=len;i++){
		
		if(data[i-1]){
			xorIndex^=i;
		}
	}
	int restitution=0;
	int sum=0;
	for(int i=0;i<lenCode-1;i++){
		if(data[i+len]){
			restitution+=(1<<i);
		}
		sum+=data[i+len];
	}
	
	int fake = xorIndex^restitution;

	vector<int> real=data;
	for(int i=0;i<lenCode;i++)real.pop_back();
	if(fake>0 && !((sum&1)!=data[data.size()-1]))
		real[fake-1] = !real[fake-1];
	
	
	return real;
}

Compilation message

transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:14:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i=1;i<=source.size();i++){
      |              ~^~~~~~~~~~~~~~~
transfer.cpp:13:6: warning: unused variable 'xor0' [-Wunused-variable]
   13 |  int xor0;
      |      ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 796 KB Output is correct
2 Correct 1 ms 784 KB Output is correct
3 Correct 1 ms 792 KB Output is correct
4 Correct 1 ms 796 KB Output is correct
5 Correct 1 ms 796 KB Output is correct
6 Correct 1 ms 796 KB Output is correct
7 Correct 1 ms 796 KB Output is correct
8 Correct 1 ms 788 KB Output is correct
9 Correct 1 ms 792 KB Output is correct
10 Correct 1 ms 796 KB Output is correct
11 Correct 1 ms 792 KB Output is correct
12 Correct 1 ms 788 KB Output is correct
13 Correct 1 ms 788 KB Output is correct
14 Correct 1 ms 1292 KB Output is correct
15 Correct 1 ms 792 KB Output is correct
16 Correct 1 ms 796 KB Output is correct
17 Correct 1 ms 788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 2504 KB Output is correct
2 Correct 34 ms 2504 KB Output is correct
3 Correct 33 ms 2516 KB Output is correct
4 Correct 39 ms 2504 KB Output is correct
5 Correct 38 ms 2508 KB Output is correct
6 Correct 44 ms 2516 KB Output is correct
7 Correct 38 ms 2520 KB Output is correct
8 Correct 32 ms 2516 KB Output is correct
9 Correct 30 ms 2508 KB Output is correct
10 Correct 29 ms 2508 KB Output is correct
11 Correct 29 ms 2508 KB Output is correct
12 Correct 31 ms 2512 KB Output is correct
13 Correct 31 ms 2512 KB Output is correct
14 Correct 36 ms 2512 KB Output is correct
15 Correct 35 ms 2512 KB Output is correct
16 Correct 38 ms 2504 KB Output is correct
17 Correct 36 ms 2516 KB Output is correct
18 Correct 35 ms 2508 KB Output is correct
19 Correct 34 ms 2596 KB Output is correct