답안 #1006158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1006158 2024-06-23T13:42:21 Z HishamAlshehri Data Transfer (IOI19_transfer) C++17
0 / 100
4 ms 2512 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> get_attachment(vector<int> source) {
	int x = 0, cnt = 0;
	for (int i = 0; i < source.size(); i++)
	{
		if (source[i])
		{
			x ^= i;
			cnt++;
		}
	}
	vector<int>ans;
	int bi = 0;
	while (x)
	{
		ans.push_back(x % 2);
		x /= 2;
	}
	ans.push_back(cnt % 2);
	return ans;
}

vector<int> retrieve(vector<int> data) {
	int x1 = 0, k = data[data.size() - 1], cnt = 0;
	for (int i = 0; i < 255; i++)
	{
		if (data[i])
		{
			cnt++;
			x1 ^= i;
		}
	}
	int x2 = 0;
	for (int i = 255; i < data.size() - 1; i++)
	{
		x2 += data[i] * (1 << i - 255);		
	}
	if (x1 != x2 && cnt % 2 != k)
		data[x2 ^ x1] ^= 1;
	return std::vector<int>(data.begin(), data.begin() + 256);
}

Compilation message

transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:6:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |  for (int i = 0; i < source.size(); i++)
      |                  ~~^~~~~~~~~~~~~~~
transfer.cpp:15:6: warning: unused variable 'bi' [-Wunused-variable]
   15 |  int bi = 0;
      |      ^~
transfer.cpp: In function 'std::vector<int> retrieve(std::vector<int>)':
transfer.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for (int i = 255; i < data.size() - 1; i++)
      |                    ~~^~~~~~~~~~~~~~~~~
transfer.cpp:38:27: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   38 |   x2 += data[i] * (1 << i - 255);
      |                         ~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1044 KB WA in grader: wrong source retrieval
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2512 KB WA in grader: wrong source retrieval
2 Halted 0 ms 0 KB -