답안 #1014158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1014158 2024-07-04T12:42:47 Z Cookie Data Transfer (IOI19_transfer) C++14
100 / 100
195 ms 2520 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
#include "transfer.h"
#include <iostream>
using namespace std;

std::vector<int> get_attachment(std::vector<int> source) {
    vt<int>res;
    int xo = 0;
	for(int i = 0; (1 << i) < sz(source); i++){
	    int bit = 0;
	    for(int j = 1; j <= sz(source); j++){
	        if((j >> i) & 1){
	            bit ^= source[j - 1];
	        }
	    }
	    res.pb(bit);
	}
	for(auto i: source)xo ^= i;
	res.pb(xo);
    //k = 9; 
    return(res);
}

std::vector<int> retrieve(std::vector<int> data) {
    int n = ((sz(data) <= 100) ? 63 : 255);
    int xo = 0;
    for(int i = 0; i < n; i++)xo ^= data[i];
    if(data.back() == xo){
        vt<int>res;
        for(int i = 0; i < n; i++)res.pb(data[i]);
        return(res);
    }
	int mask = 0;
	for(int i = 0; (1 << i) < n; i++){
	    int xo = 0;
	    for(int j = 1; j <= n; j++){
	        if((j >> i) & 1){
	            xo ^= data[j - 1];
	        }
	    }
	    if(xo != data[i + n]){
	       mask += (1 << i);
	    }
	}
	//cout << mask << " ";
	if(mask != 0){
	    data[mask - 1] = !data[mask - 1];
	}
	vt<int>res;
	for(int i = 0; i < n; i++)res.pb(data[i]);
	return(res);
}
/*
static inline string run_scenario() {
	int c;
	cin >> c;
	if (c < -1)
		return "invalid corruption index";
	string source_str;
	cin >> source_str;
	const int N = source_str.size();
	const int max_attachment_size = 2*N;
	vector<int> source;
	for (int i=0; i<N; i++)
		source.push_back(source_str[i]-'0');

    
	vector<int> attachment = get_attachment(source);
	
	if (int(attachment.size()) > max_attachment_size)
		return "attachment too large";
	for (int x : attachment)
		if (x != 0 && x != 1)
			return "invalid attachment integer value";
    
	vector<int> data(source);
	data.insert(data.end(), attachment.begin(), attachment.end());
    
	if (c >= int(data.size()))
		return "invalid corruption index";

	if (c >= 0)
		data[c] = 1-data[c];

	vector<int> result_source = retrieve(data);
    for(auto i: result_source)cout << i;
	if (source != result_source)
		return "wrong source retrieval";

	return string("OK K=")+to_string(attachment.size());
	
}
//#include "transfer.h"


int main() {
	int T;
	cin >> T;
	for (int scenario = 0; scenario < T; scenario++) {
		string result = run_scenario();
		cout << "scenario #" << scenario << ": " << result << endl;
	}
	return 0;
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 788 KB Output is correct
2 Correct 4 ms 792 KB Output is correct
3 Correct 3 ms 792 KB Output is correct
4 Correct 4 ms 784 KB Output is correct
5 Correct 4 ms 792 KB Output is correct
6 Correct 3 ms 800 KB Output is correct
7 Correct 4 ms 1052 KB Output is correct
8 Correct 4 ms 800 KB Output is correct
9 Correct 4 ms 800 KB Output is correct
10 Correct 5 ms 792 KB Output is correct
11 Correct 4 ms 792 KB Output is correct
12 Correct 4 ms 792 KB Output is correct
13 Correct 6 ms 784 KB Output is correct
14 Correct 4 ms 792 KB Output is correct
15 Correct 3 ms 1000 KB Output is correct
16 Correct 3 ms 792 KB Output is correct
17 Correct 3 ms 792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 161 ms 2508 KB Output is correct
2 Correct 151 ms 2508 KB Output is correct
3 Correct 160 ms 2504 KB Output is correct
4 Correct 185 ms 2516 KB Output is correct
5 Correct 158 ms 2516 KB Output is correct
6 Correct 195 ms 2504 KB Output is correct
7 Correct 163 ms 2504 KB Output is correct
8 Correct 161 ms 2508 KB Output is correct
9 Correct 177 ms 2516 KB Output is correct
10 Correct 162 ms 2504 KB Output is correct
11 Correct 182 ms 2504 KB Output is correct
12 Correct 175 ms 2516 KB Output is correct
13 Correct 162 ms 2508 KB Output is correct
14 Correct 163 ms 2512 KB Output is correct
15 Correct 177 ms 2512 KB Output is correct
16 Correct 164 ms 2516 KB Output is correct
17 Correct 166 ms 2520 KB Output is correct
18 Correct 195 ms 2504 KB Output is correct
19 Correct 162 ms 2504 KB Output is correct