Submission #1006189

#TimeUsernameProblemLanguageResultExecution timeMemory
1006189AliMark71Data Transfer (IOI19_transfer)C++17
Compilation error
0 ms0 KiB
#include "transfer.h" using namespace std; std::vector<int> get_attachment(std::vector<int> source) { int xorSum = 0; for (int i = 0; i < source.size(); i++) if (source[i]) xorSum ^= (i + 1); int correctionSize = __builtin_popcount((int) source.size()); vector<int> correctionData(correctionSize + 1); for (int i = 0; i < correctionSize; i++) if (xorSum&(1<<i)) correctionData[i] = 1; correctionData.back() = __builtin_popcount(xorSum) % 2; return correctionData; } std::vector<int> retrieve(std::vector<int> data) { int baseSize = (data.size() == 70 ? 6 : 8); vector<int> possibleSource(data.begin(), data.begin() + (1<<baseSize) - 1); vector<int> correctionData(data.begin() + possibleSource.size(), data.end()); if (count_if(correctionData.begin(), correctionData.end() - 1, [](int a){ return a == 1; }) % 2 == correctionData.back()) { int checkSum = 0; for (int i = 0, val = 1; i < correctionData.size() - 1; i++, val *= 2) checkSum += correctionData[i] * val; int expectedCheckSum = 0; for (int i = 0; i < possibleSource.size(); i++) if (possibleSource[i]) expectedCheckSum ^= (i + 1); if (checkSum != expectedCheckSum) { int errorPos = checkSum ^ expectedCheckSum; possibleSource[errorPos - 1] ^= 1; } } return possibleSource; }

Compilation message (stderr)

transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:7:23: 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++) if (source[i]) xorSum ^= (i + 1);
      |                     ~~^~~~~~~~~~~~~~~
transfer.cpp: In function 'std::vector<int> retrieve(std::vector<int>)':
transfer.cpp:24:9: error: 'count_if' was not declared in this scope
   24 |     if (count_if(correctionData.begin(), correctionData.end() - 1,
      |         ^~~~~~~~
transfer.cpp:27:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         for (int i = 0, val = 1; i < correctionData.size() - 1; i++, val *= 2) checkSum += correctionData[i] * val;
      |                                  ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
transfer.cpp:30:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for (int i = 0; i < possibleSource.size(); i++) if (possibleSource[i]) expectedCheckSum ^= (i + 1);
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~