Submission #573166

# Submission time Handle Problem Language Result Execution time Memory
573166 2022-06-06T08:12:48 Z Jomnoi Data Transfer (IOI19_transfer) C++17
100 / 100
79 ms 2500 KB
#include <bits/stdc++.h>
#include "transfer.h"
using namespace std;

vector <int> get_attachment(vector <int> source) {
	int X = 0, cnt1 = 0, sz = log2(source.size() + 1);
	for(int i = 0; i < source.size(); i++) {
		if(source[i] == 1) {
			X ^= (i + 1);
		}
	}

	vector <int> K;
	while(X > 0 or K.size() < sz) {
		K.push_back(X % 2);
		cnt1 += X % 2;
		X /= 2;
	}
	K.push_back(cnt1 % 2);

	return K;
}

vector <int> retrieve(vector <int> data) {
	int cnt1 = data.back(), sz = log2(data.size()), X = 0;
	data.pop_back();

	while(sz--) {
		X *= 2;
		X += data.back();
		cnt1 += data.back();
		data.pop_back();
	}

	if(cnt1 % 2 == 1) {
		return data;
	}

	for(int i = 0; i < data.size(); i++) {
		if(data[i] == 1) {
			X ^= (i + 1);
		}
	}

	if(X != 0) {
		data[X - 1] ^= 1;
	}
	return data;
}

Compilation message

transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:7:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |  for(int i = 0; i < source.size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~
transfer.cpp:14:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   14 |  while(X > 0 or K.size() < sz) {
      |                 ~~~~~~~~~^~~~
transfer.cpp: In function 'std::vector<int> retrieve(std::vector<int>)':
transfer.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(int i = 0; i < data.size(); i++) {
      |                 ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 644 KB Output is correct
2 Correct 2 ms 644 KB Output is correct
3 Correct 4 ms 656 KB Output is correct
4 Correct 3 ms 652 KB Output is correct
5 Correct 3 ms 644 KB Output is correct
6 Correct 3 ms 644 KB Output is correct
7 Correct 2 ms 652 KB Output is correct
8 Correct 3 ms 652 KB Output is correct
9 Correct 2 ms 732 KB Output is correct
10 Correct 2 ms 652 KB Output is correct
11 Correct 3 ms 644 KB Output is correct
12 Correct 3 ms 732 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 3 ms 644 KB Output is correct
15 Correct 3 ms 652 KB Output is correct
16 Correct 2 ms 644 KB Output is correct
17 Correct 3 ms 740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 2400 KB Output is correct
2 Correct 40 ms 2500 KB Output is correct
3 Correct 43 ms 2496 KB Output is correct
4 Correct 46 ms 2496 KB Output is correct
5 Correct 77 ms 2496 KB Output is correct
6 Correct 79 ms 2448 KB Output is correct
7 Correct 69 ms 2456 KB Output is correct
8 Correct 54 ms 2488 KB Output is correct
9 Correct 40 ms 2496 KB Output is correct
10 Correct 39 ms 2488 KB Output is correct
11 Correct 43 ms 2488 KB Output is correct
12 Correct 41 ms 2488 KB Output is correct
13 Correct 41 ms 2492 KB Output is correct
14 Correct 40 ms 2496 KB Output is correct
15 Correct 56 ms 2488 KB Output is correct
16 Correct 55 ms 2496 KB Output is correct
17 Correct 46 ms 2496 KB Output is correct
18 Correct 43 ms 2444 KB Output is correct
19 Correct 42 ms 2500 KB Output is correct