제출 #143837

#제출 시각아이디문제언어결과실행 시간메모리
143837SpeedOfMagicData Transfer (IOI19_transfer)C++17
100 / 100
161 ms2652 KiB
#include "transfer.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> get_attachment(vector<int> source) {
	int x = 0;
	vector<int> res;
	
	for (int i = 0; i < source.size(); i++)
		x ^= (i + 1) * source[i];
	
	int lim = (source.size() == 63) ? 6 : 8;
	int X = 0;
	for (int i = 0; i < lim; i++) {
		int d = (x & (1 << i)) != 0;
		res.push_back(d);
		X ^= d;
	}
	
	res.push_back(X);
	return res;
}

vector<int> retrieve(vector<int> data) {
	//for (int i = 0; i < data.size(); i++) cout << data[i]; cout << endl;
	int st;
	int len;
	if (data.size() == 70) {
		st = 63;
		len = 6;
	} else {
		st = 255;
		len = 8;
	}
	
	int x = 0;
	int X = 0;
	for (int i = st; i < st + len; i++) {
		x += (1 << (i - st)) * data[i];
		X ^= data[i];
	}
	
	int rx = 0;
	for (int i = 0; i < st; i++)
		rx ^= (i + 1) * data[i];
	
	vector<int> ans;
	if (x != rx) {
		if (X != data.back()) { //problem with xor
			for (int i = 0; i < st; i++)
				ans.push_back(data[i]);
		} else { //problem with the main part
			for (int i = 0; i < st; i++) {
				if ((rx ^ (i + 1)) == x)
					ans.push_back(1 - data[i]);
				else
					ans.push_back(data[i]);
			}
		}
	} else //problem with the last bit, or there's no problem
		for (int i = 0; i < st; i++)
			ans.push_back(data[i]);
	//for (int i : ans) cout << i; cout << endl;
	
	return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:9:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < source.size(); i++)
                  ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...