Submission #98199

#TimeUsernameProblemLanguageResultExecution timeMemory
98199SpeedOfMagicParrots (IOI11_parrots)C++17
Compilation error
0 ms0 KiB
#include "grader.h"
#include <bits/stdc++.h>
using namespace std;

map<int, int> hsh;
vector<int> invHsh;
bool inverse[6] = {0, 0, 0, 0, 0, 0};
void encode(int N, int M[]) {
	int p = 0;
	for (int i = 0; i < N; i++)
		hsh[M[i]] = 0;
	for (auto i : hsh) {
		invHsh.push_back(i.first);
		hsh[i.first] = p++;
	}
	for (int i = 0; i < N; i++) 
		M[i] = hsh[M[i]];
	
	//for (int i =0 ; i < N; i++) cout << M[i] << " "; cout << endl;
	
	int cnt[6] = {0, 0, 0, 0, 0, 0};
	for (int i = 0; i < N; i++) 
		for (int j = 0; j < 6; j++)
			if (M[i] & (1 << j))
				cnt[j]++;
			
	for (int i = 0; i < 6; i++)
		if (cnt[i] > N / 2)
			inverse[i] = 1;
	
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 6; j++) {
			if (inverse[j])
				M[i] ^= (1 << j);
			if (M[i] & (1 << j)) {
				send((i << 2) + (j % 4)); //location, then number of bit = 1
				if (j > 3)
					send((i << 2) + (j % 4));
			}
		}
	}
}
void decode(int N, int L, int X[]) {
	int res[N];
	int cnt[N][4];
	memset(cnt, 0, sizeof cnt);
	memset(res, 0, sizeof res);
	for (int i = 0; i < L; i++) {
		int ind = X[i] >> 2;
		int num = X[i] % 4;
		cnt[ind][num]++;
	}
	
	for (int i = 0; i < N; i++)
		for (int j = 0; j < 4; j++) {
			assert(cnt[i][j] <= 3);
			if (cnt[i][j] % 2)
				res[i] += (1 << j);
			if (cnt[i][j] > 1)
				res[i] += (1 << (j + 4));
		}
	
	for (int i : res) {
		for (int j = 0; j < 6; j++)
			if (inverse[j])
				i ^= (1 << j);
		//cout << i << " " << invHsh[i]; cout << endl;
		output(invHsh[i]);
	}
}

Compilation message (stderr)

encoder.cpp:1:10: fatal error: grader.h: No such file or directory
 #include "grader.h"
          ^~~~~~~~~~
compilation terminated.

decoder.cpp: In function 'void decode(int, int, int*)':
decoder.cpp:4:2: error: 'memset' was not declared in this scope
  memset(cnt, 0, sizeof cnt);
  ^~~~~~
decoder.cpp:14:4: error: 'assert' was not declared in this scope
    assert(cnt[i][j] <= 3);
    ^~~~~~
decoder.cpp:14:4: note: suggested alternative: 'short'
    assert(cnt[i][j] <= 3);
    ^~~~~~
    short
decoder.cpp:23:8: error: 'inverse' was not declared in this scope
    if (inverse[j])
        ^~~~~~~
decoder.cpp:26:10: error: 'invHsh' was not declared in this scope
   output(invHsh[i]);
          ^~~~~~
decoder.cpp:26:3: error: 'output' was not declared in this scope
   output(invHsh[i]);
   ^~~~~~