Submission #829713

# Submission time Handle Problem Language Result Execution time Memory
829713 2023-08-18T14:20:53 Z haxorman Data Transfer (IOI19_transfer) C++14
100 / 100
163 ms 2516 KB
#include "transfer.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> get_attachment(vector<int> source) {
    int end = 0;
    vector<int> res;
    for (int j = 0; (1 << j) < source.size(); ++j) {
        int val = 0;
        for (int i = 0; i < source.size(); ++i) {
            if ((i + 1) & (1 << j)) {
                val ^= source[i];
            }
        }
        res.push_back(val);
        end ^= val;
    }
    res.push_back(end);

    return res;
}

vector<int> retrieve(vector<int> data) {
    bool smol = (data.size() == 70);
    vector<int> source;
    for (int i = 0; i < data.size() - (smol ? 7 : 9); ++i) {
        source.push_back(data[i]);
    }
    
    int end = 0;
    vector<int> lst;
    for (int i = data.size() - (smol ? 7 : 9); i < data.size() - 1; ++i) {
        lst.push_back(data[i]);
        end ^= data[i];
    }

    if (end != data.back()) {
        return source;
    }
    
    int bad = 0, tot = 0;
    for (int j = 0; (1 << j) < source.size(); ++j) {
        int val = 0;
        for (int i = 0; i < source.size(); ++i) {
            if ((i + 1) & (1 << j)) {
                val ^= source[i];
            }
        }
        if (val != lst[j]) {
            bad += (1 << j);
        }
    }
    
    if (bad) {
        source[bad - 1] ^= 1;
    }
    return source;
}

Compilation message

transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:8:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for (int j = 0; (1 << j) < source.size(); ++j) {
      |                     ~~~~~~~~~^~~~~~~~~~~~~~~
transfer.cpp:10:27: 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:26:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int i = 0; i < data.size() - (smol ? 7 : 9); ++i) {
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
transfer.cpp:32:50: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i = data.size() - (smol ? 7 : 9); i < data.size() - 1; ++i) {
      |                                                ~~^~~~~~~~~~~~~~~~~
transfer.cpp:42:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for (int j = 0; (1 << j) < source.size(); ++j) {
      |                     ~~~~~~~~~^~~~~~~~~~~~~~~
transfer.cpp:44:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for (int i = 0; i < source.size(); ++i) {
      |                         ~~^~~~~~~~~~~~~~~
transfer.cpp:41:18: warning: unused variable 'tot' [-Wunused-variable]
   41 |     int bad = 0, tot = 0;
      |                  ^~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 648 KB Output is correct
2 Correct 4 ms 644 KB Output is correct
3 Correct 3 ms 648 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 4 ms 644 KB Output is correct
6 Correct 4 ms 648 KB Output is correct
7 Correct 3 ms 648 KB Output is correct
8 Correct 4 ms 640 KB Output is correct
9 Correct 3 ms 648 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 4 ms 648 KB Output is correct
12 Correct 3 ms 640 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
14 Correct 3 ms 644 KB Output is correct
15 Correct 3 ms 648 KB Output is correct
16 Correct 4 ms 640 KB Output is correct
17 Correct 3 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 2516 KB Output is correct
2 Correct 155 ms 2484 KB Output is correct
3 Correct 163 ms 2484 KB Output is correct
4 Correct 153 ms 2484 KB Output is correct
5 Correct 155 ms 2484 KB Output is correct
6 Correct 156 ms 2496 KB Output is correct
7 Correct 153 ms 2488 KB Output is correct
8 Correct 153 ms 2484 KB Output is correct
9 Correct 155 ms 2492 KB Output is correct
10 Correct 161 ms 2488 KB Output is correct
11 Correct 156 ms 2492 KB Output is correct
12 Correct 159 ms 2408 KB Output is correct
13 Correct 160 ms 2492 KB Output is correct
14 Correct 157 ms 2496 KB Output is correct
15 Correct 152 ms 2492 KB Output is correct
16 Correct 155 ms 2496 KB Output is correct
17 Correct 152 ms 2484 KB Output is correct
18 Correct 162 ms 2484 KB Output is correct
19 Correct 157 ms 2496 KB Output is correct