답안 #213573

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
213573 2020-03-26T07:48:11 Z _Ice_Tea_ Data Transfer (IOI19_transfer) C++14
100 / 100
337 ms 2924 KB
#include<bits/stdc++.h>
#include "transfer.h"

#define de(x) if( x && x == MODE)
#define MODE 0

using namespace std;

std::vector<int> get_attachment(std::vector<int> source) {

	int i,j,k;

	int N = source.size();
	int L = ( N == 63 ? 6 : 8 );
	// int L = 3;

	vector<int> attach;
	for( i=0; i<L; i++)
	{
		int key = 0;
		for( j=0; j<N; j++)
		{
			if( (j>>i)&1 )
				continue;
			key ^= source[j];
		}
		attach.push_back(key);
	}

	int key = 0;
	for( auto it:attach)
		key ^= it;
	attach.push_back(key);
	de(1)
	{
		printf(">>> ");
		for( auto it:attach)
			printf("%d ", it);
		printf("\n");
	}

	return attach;
}

std::vector<int> retrieve(std::vector<int> data) {

	int i,j;

	int N = ( data.size() == 70 ? 63 : 255);
	// int N = 7;
	int L = data.size() - N - 1;

	vector<int> ans;
	int arr[256];

	int idx = 0;
	for( i=0; i<L; i++)
	{
		int key = 0;
		for( j=0; j<N; j++)
		{
			if( (j>>i)&1 )
				continue;
			key ^= data[j];
		}

		if( key == data[ N+i ])
			idx ^= (1<<i);
	}

	de(1) printf("idx = %d\n", idx);

	for( i=0; i<N; i++)
		ans.push_back( data[i] );
	if( idx == N)
	{
		// return ans;
	}
	else
	{
		int key = 0;
		for( i=0; i<L; i++)
			key ^= data[ N+i ];

		if( key != data.back())
		{
			// return ans;
		}
		else
		{
			ans[idx] ^= 1;
			// return ans;
		}
	}

	de(1)
	{
		printf("ans = ");
		for( auto it: ans)
			printf("%d", it);
		printf("\n");
	}
	return ans;
}

Compilation message

transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:11:10: warning: unused variable 'k' [-Wunused-variable]
  int i,j,k;
          ^
transfer.cpp: In function 'std::vector<int> retrieve(std::vector<int>)':
transfer.cpp:54:6: warning: unused variable 'arr' [-Wunused-variable]
  int arr[256];
      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 1148 KB Output is correct
2 Correct 16 ms 1156 KB Output is correct
3 Correct 16 ms 1140 KB Output is correct
4 Correct 16 ms 1144 KB Output is correct
5 Correct 16 ms 1156 KB Output is correct
6 Correct 16 ms 1144 KB Output is correct
7 Correct 16 ms 1152 KB Output is correct
8 Correct 16 ms 1076 KB Output is correct
9 Correct 16 ms 1152 KB Output is correct
10 Correct 16 ms 1160 KB Output is correct
11 Correct 16 ms 1148 KB Output is correct
12 Correct 16 ms 1152 KB Output is correct
13 Correct 16 ms 1076 KB Output is correct
14 Correct 17 ms 1156 KB Output is correct
15 Correct 16 ms 1148 KB Output is correct
16 Correct 16 ms 1152 KB Output is correct
17 Correct 16 ms 1292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 331 ms 2668 KB Output is correct
2 Correct 326 ms 2664 KB Output is correct
3 Correct 324 ms 2672 KB Output is correct
4 Correct 320 ms 2672 KB Output is correct
5 Correct 326 ms 2672 KB Output is correct
6 Correct 328 ms 2676 KB Output is correct
7 Correct 323 ms 2668 KB Output is correct
8 Correct 320 ms 2676 KB Output is correct
9 Correct 324 ms 2676 KB Output is correct
10 Correct 319 ms 2672 KB Output is correct
11 Correct 334 ms 2676 KB Output is correct
12 Correct 321 ms 2672 KB Output is correct
13 Correct 323 ms 2424 KB Output is correct
14 Correct 325 ms 2924 KB Output is correct
15 Correct 325 ms 2676 KB Output is correct
16 Correct 323 ms 2680 KB Output is correct
17 Correct 324 ms 2680 KB Output is correct
18 Correct 323 ms 2668 KB Output is correct
19 Correct 337 ms 2664 KB Output is correct