Submission #352027

#TimeUsernameProblemLanguageResultExecution timeMemory
352027tengiz05Parrots (IOI11_parrots)C++17
52 / 100
5 ms1588 KiB
#include "encoder.h"
#include "encoderlib.h"
#include <bits/stdc++.h>
using namespace std;
void print(int x){
	for(int i=128;i>=0;i>>=1){
		cout << ((x>>i)&1);
	}cout << '\n';
}
int A[100];
void encode(int n, int aa[]){
	for(int i=0;i<n;i++)A[i] = aa[i];
	int best_xor = 0;
	for(int j=0;j<8;j++){
		int cnt = 0;
		for(int i=0;i<n;i++){
			cnt += (A[i]>>1&1);
		}if(cnt > n/2)best_xor |= (1<<j);
	}
	send(best_xor);
	send(best_xor);
	send(best_xor);
	send(best_xor);
	for(int i=0;i<n;i++)A[i] ^= best_xor;
	for(int i=0;i<n;i++){
		while(A[i] >= 128){
			A[i] -= 128;
			send(i | (7<<5));
		}
		while(A[i] >= 64){
			A[i] -= 64;
			send(i | (6<<5));
		}
		while(A[i] >= 32){
			A[i] -= 32;
			send(i | (5<<5));
		}
		while(A[i] >= 16){
			A[i] -= 16;
			send(i | (4<<5));
		}
		while(A[i] >= 8){
			A[i] -= 8;
			send(i | (3<<5));
		}
		while(A[i] >= 4){
			A[i] -= 4;
			send(i | (2<<5));
		}
		while(A[i] >= 2){
			A[i] -= 2;
			send(i | (1<<5));
		}
		while(A[i] >= 1){
			A[i] -= 1;
			send(i | (0<<5));
		}
	}
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
using namespace std;
int a[256], cnt[256];
void decode(int n, int len, int x[]){
	for(int i=0;i<256;i++)a[i]=0,cnt[i]=0;
	for(int i=0;i<len;i++)cnt[x[i]]++;
	int best_xor;
	for(int i=0;i<256;i++){
		if(cnt[i] > 3){
			cnt[i] -= 4;
			best_xor = i;
			break;
		}
	}
	for(int i=0;i<len;i++){
		int type = (x[i] & (224))>>5;
		int ind = x[i] & 31;
		if(type == 7)a[ind] += 128,cnt[x[i]]--;
		if(!cnt[x[i]])continue;
		if(type == 6)a[ind] += 64,cnt[x[i]]--;
		if(!cnt[x[i]])continue;
		if(type == 5)a[ind] += 32,cnt[x[i]]--;
		if(!cnt[x[i]])continue;
		if(type == 4)a[ind] += 16,cnt[x[i]]--;
		if(!cnt[x[i]])continue;
		if(type == 3)a[ind] += 8,cnt[x[i]]--;
		if(!cnt[x[i]])continue;
		if(type == 2)a[ind] += 4,cnt[x[i]]--;
		if(!cnt[x[i]])continue;
		if(type == 1)a[ind] += 2,cnt[x[i]]--;
		if(!cnt[x[i]])continue;
		if(type == 0)a[ind] += 1,cnt[x[i]]--;
		if(!cnt[x[i]])continue;
	}
	//~ for(int i=0;i<n;i++)cout << a[i] << ' ';cout << '\n';	
	for(int i=0;i<n;i++)output(a[i]^best_xor);
}

Compilation message (stderr)

decoder.cpp: In function 'void decode(int, int, int*)':
decoder.cpp:38:28: warning: 'best_xor' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |  for(int i=0;i<n;i++)output(a[i]^best_xor);
      |                      ~~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...