답안 #990636

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
990636 2024-05-30T21:02:44 Z aaaaaarroz Data Transfer (IOI19_transfer) C++17
100 / 100
46 ms 2592 KB
#include "transfer.h"


std::vector<int> get_attachment(std::vector<int> source) {

	std::vector<int> v;

	int x = 0;

	for (int i = 0; i < source.size(); i++)

		if (source[i]) x ^= (i + 1);


	int last = 0;

	if (source.size() < 64) {

		for (int i = 0; i < 6; i++) {

			v.push_back(x & 1);

			if (x & 1) last = 1 - last;

			x >>= 1;

		}

	} else {

		for (int i = 0; i < 8; i++) {

			v.push_back(x & 1);

			if (x & 1) last = 1 - last;

			x >>= 1;

		}

	}

	v.push_back(last);

	return v;

}


std::vector<int> retrieve(std::vector<int> data) {

	int last = data.back();

	data.pop_back();

	int actual_last = 0, x = 0;

	if (data.size() < 71) {

		for (int i = 0; i < 6; i++) {

			x <<= 1;

			x += data.back();

			if (data.back()) actual_last = 1 - actual_last;

			data.pop_back();

		}

	} else {

		for (int i = 0; i < 8; i++) {

			x <<= 1;

			x += data.back();

			if (data.back()) actual_last = 1 - actual_last;

			data.pop_back();

		}

	}


	if (actual_last != last) return std::vector<int>(data.begin(), data.end());


	int actual_x = 0;

	for (int i = 0; i < data.size(); i++) {

		if (data[i]) actual_x ^= (i + 1);

	}


	int error = actual_x ^ x;

	if (error == 0) return data;


	data[error - 1] = 1 - data[error - 1];

	return data;

}

Compilation message

transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:10:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for (int i = 0; i < source.size(); i++)
      |                  ~~^~~~~~~~~~~~~~~
transfer.cpp: In function 'std::vector<int> retrieve(std::vector<int>)':
transfer.cpp:94:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |  for (int i = 0; i < data.size(); i++) {
      |                  ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 800 KB Output is correct
2 Correct 1 ms 800 KB Output is correct
3 Correct 1 ms 792 KB Output is correct
4 Correct 1 ms 800 KB Output is correct
5 Correct 1 ms 800 KB Output is correct
6 Correct 1 ms 800 KB Output is correct
7 Correct 1 ms 800 KB Output is correct
8 Correct 1 ms 792 KB Output is correct
9 Correct 2 ms 800 KB Output is correct
10 Correct 1 ms 800 KB Output is correct
11 Correct 2 ms 800 KB Output is correct
12 Correct 1 ms 792 KB Output is correct
13 Correct 1 ms 800 KB Output is correct
14 Correct 2 ms 1040 KB Output is correct
15 Correct 1 ms 796 KB Output is correct
16 Correct 2 ms 800 KB Output is correct
17 Correct 1 ms 792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2512 KB Output is correct
2 Correct 46 ms 2520 KB Output is correct
3 Correct 33 ms 2516 KB Output is correct
4 Correct 46 ms 2508 KB Output is correct
5 Correct 34 ms 2516 KB Output is correct
6 Correct 33 ms 2516 KB Output is correct
7 Correct 35 ms 2508 KB Output is correct
8 Correct 29 ms 2516 KB Output is correct
9 Correct 30 ms 2508 KB Output is correct
10 Correct 27 ms 2516 KB Output is correct
11 Correct 30 ms 2504 KB Output is correct
12 Correct 31 ms 2512 KB Output is correct
13 Correct 30 ms 2508 KB Output is correct
14 Correct 29 ms 2516 KB Output is correct
15 Correct 30 ms 2516 KB Output is correct
16 Correct 31 ms 2516 KB Output is correct
17 Correct 45 ms 2516 KB Output is correct
18 Correct 38 ms 2592 KB Output is correct
19 Correct 31 ms 2508 KB Output is correct