답안 #679261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
679261 2023-01-08T00:18:45 Z That_Salamander Data Transfer (IOI19_transfer) C++14
100 / 100
246 ms 2500 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

vector<int> get_attachment(vector<int> source) {
    vector<int> hamming;

    int m = 1;
    int x2 = 0;
    while (m <= source.size()) {
        int x = 0;
        for (int i = 0; i < source.size(); i++) {
            if (!(i & m)) {
                x ^= source[i];
            }
        }
        hamming.push_back(x);
        x2 ^= x;

        m <<= 1;
    }

    hamming.push_back(x2);
    return hamming;
}

vector<int> retrieve(vector<int> data) {
    int n = data.size() >= 255 ? 255 : 63;
    int h = data.size() - n - 1;

    vector<int> source(data.begin(), data.begin()+ n);

    vector<int> hamming(h);

    int x = 0;
    for (int i = 0; i < h; i++) {
        x ^= hamming[i] = data[n + i];
    }

    if (x != data[n + h]) return source;

    vector<int> correct(h);
    bool valid = true;
    for (int i = 0; i < h; i++) {
        int x = 0;
        for (int j = 0; j < n; j++) {
            if (!((j >> i) & 1)) {
                x ^= source[j];
            }
        }

        correct[i] = x == hamming[i];
        if (!correct[i]) valid = false;
    }

    if (valid) return source;

    int idx = 0;
    for (int i = 0; i < h; i++) {
        if (correct[i]) {
            idx += 1 << i;
        }
    }

    source[idx] ^= 1;

    return source;
}

#ifdef LOCAL_TEST
#include <random>

vector<int> manipulate(vector<int>& data) {
    vector<int> res = data;
    
    if (rand() % 2) {
        res[rand() % res.size()] ^= 1;
    }

    return res;
}

void doTest() {
    int n = rand() % 2 ? 63 : 255;

    vector<int> data(n);
    for (int& x: data) {
        x = rand() % 2;
    }

    vector<int> attached = data;
    for (int x: get_attachment(data)) {
        attached.push_back(x);
    }

    if (retrieve(manipulate(attached)) != data) {
        cout << "Error!" << endl;
    }
}

int main() {
    for (int i = 0; i < 200000; i++) {
        doTest();
    }

    cout << "Finished!" << endl;
}
#endif

Compilation message

transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:11:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     while (m <= source.size()) {
      |            ~~^~~~~~~~~~~~~~~~
transfer.cpp:13:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |         for (int i = 0; i < source.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 644 KB Output is correct
3 Correct 5 ms 644 KB Output is correct
4 Correct 6 ms 648 KB Output is correct
5 Correct 6 ms 740 KB Output is correct
6 Correct 5 ms 652 KB Output is correct
7 Correct 5 ms 644 KB Output is correct
8 Correct 4 ms 740 KB Output is correct
9 Correct 5 ms 732 KB Output is correct
10 Correct 5 ms 652 KB Output is correct
11 Correct 5 ms 644 KB Output is correct
12 Correct 4 ms 728 KB Output is correct
13 Correct 4 ms 648 KB Output is correct
14 Correct 5 ms 664 KB Output is correct
15 Correct 5 ms 644 KB Output is correct
16 Correct 5 ms 644 KB Output is correct
17 Correct 5 ms 644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 201 ms 2492 KB Output is correct
2 Correct 207 ms 2488 KB Output is correct
3 Correct 193 ms 2448 KB Output is correct
4 Correct 209 ms 2496 KB Output is correct
5 Correct 201 ms 2488 KB Output is correct
6 Correct 197 ms 2500 KB Output is correct
7 Correct 246 ms 2488 KB Output is correct
8 Correct 196 ms 2500 KB Output is correct
9 Correct 194 ms 2492 KB Output is correct
10 Correct 242 ms 2488 KB Output is correct
11 Correct 195 ms 2488 KB Output is correct
12 Correct 209 ms 2496 KB Output is correct
13 Correct 201 ms 2452 KB Output is correct
14 Correct 195 ms 2500 KB Output is correct
15 Correct 215 ms 2488 KB Output is correct
16 Correct 213 ms 2496 KB Output is correct
17 Correct 220 ms 2488 KB Output is correct
18 Correct 200 ms 2488 KB Output is correct
19 Correct 198 ms 2488 KB Output is correct