Submission #401219

# Submission time Handle Problem Language Result Execution time Memory
401219 2021-05-09T15:56:53 Z rocks03 Data Transfer (IOI19_transfer) C++14
100 / 100
82 ms 2544 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << " "
#define nl cout << "\n"
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<int> get_attachment(vector<int> source) {
    int N = SZ(source), K;
    if(N == 63) K = 6;
    else if(N == 255) K = 8;
    int x = 0, s = 0;
    rep(i, 0, N){
        if(source[i] == 1) x ^= (i + 1), s++;
    }
    vector<int> ans;
    rep(i, 0, K) ans.pb((x >> i) & 1);
    ans.pb(s % 2);
    return ans;
}

vector<int> retrieve(vector<int> data){
    int N = SZ(data), K;
    if(N >= 255) N = 255, K = 8;
    else N = 63, K = 6;
    int x = 0, s = 0;
    rep(i, 0, N){
        if(data[i] == 1) x ^= (i + 1), s++;
    }
    int x2 = 0;
    rep(i, 0, K) if(data[N + i] == 1) x2 ^= (1 << i);
    vector<int> ans;
    if(x == x2 || s % 2 == data.back()) ans = vector<int>(data.begin(), data.begin() + N);
    else{
        data[(x ^ x2) - 1] ^= 1;
        ans = vector<int>(data.begin(), data.begin() + N);
    }
    return ans;
}

Compilation message

transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:13:41: warning: 'K' may be used uninitialized in this function [-Wmaybe-uninitialized]
   13 | #define rep(i, a, b) for(int i = (a); i < (b); i++)
      |                                         ^
transfer.cpp:18:25: note: 'K' was declared here
   18 |     int N = SZ(source), K;
      |                         ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 764 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 3 ms 752 KB Output is correct
4 Correct 4 ms 752 KB Output is correct
5 Correct 4 ms 752 KB Output is correct
6 Correct 4 ms 724 KB Output is correct
7 Correct 4 ms 752 KB Output is correct
8 Correct 3 ms 752 KB Output is correct
9 Correct 4 ms 720 KB Output is correct
10 Correct 3 ms 764 KB Output is correct
11 Correct 3 ms 724 KB Output is correct
12 Correct 4 ms 752 KB Output is correct
13 Correct 3 ms 752 KB Output is correct
14 Correct 4 ms 752 KB Output is correct
15 Correct 3 ms 976 KB Output is correct
16 Correct 3 ms 752 KB Output is correct
17 Correct 3 ms 752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 2480 KB Output is correct
2 Correct 60 ms 2480 KB Output is correct
3 Correct 61 ms 2472 KB Output is correct
4 Correct 65 ms 2472 KB Output is correct
5 Correct 74 ms 2472 KB Output is correct
6 Correct 82 ms 2544 KB Output is correct
7 Correct 71 ms 2472 KB Output is correct
8 Correct 72 ms 2472 KB Output is correct
9 Correct 62 ms 2472 KB Output is correct
10 Correct 61 ms 2472 KB Output is correct
11 Correct 61 ms 2472 KB Output is correct
12 Correct 63 ms 2480 KB Output is correct
13 Correct 62 ms 2480 KB Output is correct
14 Correct 61 ms 2472 KB Output is correct
15 Correct 64 ms 2476 KB Output is correct
16 Correct 73 ms 2476 KB Output is correct
17 Correct 65 ms 2472 KB Output is correct
18 Correct 65 ms 2480 KB Output is correct
19 Correct 78 ms 2444 KB Output is correct