Submission #247445

# Submission time Handle Problem Language Result Execution time Memory
247445 2020-07-11T11:58:54 Z stoyan_malinin Data Transfer (IOI19_transfer) C++14
100 / 100
93 ms 2776 KB
#include "transfer.h"
//#include "grader.cpp"

#include<iostream>
#include<vector>

using namespace std;

int BITCnt;

vector<int> get_attachment(vector<int> source)
{
    if(source.size()==63) BITCnt = 6;
    else BITCnt = 8;

    int val1 = 0, val2 = 0;
    for(int i = 0;i<source.size();i++)
    {
        if(source[i]==1)
        {
            val1 ^= 1;
            val2 ^= i + 1;
        }
    }

    vector <int> out;
    for(int bit = 0;bit<BITCnt;bit++) out.push_back(((val2>>bit)&1));
    out.push_back(val1);

    return out;
}

vector<int> retrieve(vector<int> data)
{
    if(data.size()==70) BITCnt = 6;
    else BITCnt = 8;

    vector <int> info;
    int val1 = 0, val2 = 0;
    int expectedVal1 = 0, expectedVal2 = 0;

    info = vector <int>(data.begin(), data.begin()+(data.size()-(BITCnt+1)));
    for(int i = 0;i<info.size();i++)
    {
        if(info[i]==1)
        {
            val1 ^= 1;
            val2 ^= i + 1;
        }
    }

    for(int i = (data.size()-(BITCnt+1));i<data.size()-1;i++) expectedVal2 += (data[i]<<(i-(data.size()-(BITCnt+1))));
    expectedVal1 = data.back();

    if(val1==expectedVal1 || val2==expectedVal2) return info;
    for(int i = 0;i<info.size();i++)
    {
        if((val2^(i+1))==expectedVal2)
        {
            info[i] ^= 1;
            return info;
        }
    }
}

Compilation message

transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:17:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<source.size();i++)
                   ~^~~~~~~~~~~~~~
transfer.cpp: In function 'std::vector<int> retrieve(std::vector<int>)':
transfer.cpp:43:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<info.size();i++)
                   ~^~~~~~~~~~~~
transfer.cpp:52:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = (data.size()-(BITCnt+1));i<data.size()-1;i++) expectedVal2 += (data[i]<<(i-(data.size()-(BITCnt+1))));
                                          ~^~~~~~~~~~~~~~
transfer.cpp:56:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<info.size();i++)
                   ~^~~~~~~~~~~~
transfer.cpp:64:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1044 KB Output is correct
2 Correct 12 ms 1152 KB Output is correct
3 Correct 12 ms 1120 KB Output is correct
4 Correct 12 ms 1036 KB Output is correct
5 Correct 13 ms 1144 KB Output is correct
6 Correct 12 ms 1036 KB Output is correct
7 Correct 12 ms 1152 KB Output is correct
8 Correct 12 ms 1144 KB Output is correct
9 Correct 12 ms 1036 KB Output is correct
10 Correct 13 ms 896 KB Output is correct
11 Correct 12 ms 1036 KB Output is correct
12 Correct 12 ms 1132 KB Output is correct
13 Correct 12 ms 1160 KB Output is correct
14 Correct 13 ms 1144 KB Output is correct
15 Correct 12 ms 1132 KB Output is correct
16 Correct 12 ms 1144 KB Output is correct
17 Correct 12 ms 1036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 2668 KB Output is correct
2 Correct 72 ms 2776 KB Output is correct
3 Correct 74 ms 2648 KB Output is correct
4 Correct 78 ms 2668 KB Output is correct
5 Correct 93 ms 2632 KB Output is correct
6 Correct 87 ms 2640 KB Output is correct
7 Correct 80 ms 2680 KB Output is correct
8 Correct 86 ms 2624 KB Output is correct
9 Correct 71 ms 2664 KB Output is correct
10 Correct 71 ms 2680 KB Output is correct
11 Correct 69 ms 2672 KB Output is correct
12 Correct 74 ms 2496 KB Output is correct
13 Correct 73 ms 2752 KB Output is correct
14 Correct 70 ms 2664 KB Output is correct
15 Correct 71 ms 2680 KB Output is correct
16 Correct 73 ms 2672 KB Output is correct
17 Correct 77 ms 2668 KB Output is correct
18 Correct 75 ms 2668 KB Output is correct
19 Correct 71 ms 2652 KB Output is correct