제출 #1339654

#제출 시각아이디문제언어결과실행 시간메모리
1339654SmuggingSpun앵무새 (IOI11_parrots)C++20
81 / 100
9 ms840 KiB
#include "encoder.h"
#include "encoderlib.h"
#include<bits/stdc++.h>
using namespace std;
int ptr = 0, rdh[64][256];
void sendbit(int x){
	if(x){
    send(ptr);
  }
	else{
    ptr++;
  }
}
void encode(int n, int m[]){
	mt19937 rng(36);
	for(int i = 0; i < n; i++){
    iota(rdh[i], rdh[i] + 256, 0);
    shuffle(rdh[i], rdh[i] + 256, rng);
	}
	int cnt = ptr = 0;
	for(int i = 0; i < n; i++){
		int tval = rdh[i][m[i]];
		cnt += __builtin_popcount(tval);
	}
	int swapped = cnt < (n << 2);
	sendbit(swapped);
	for(int i = 0; i < n; i++){
		int tval = rdh[i][m[i]];
		for(int j = 0; j < 8; j++){
      sendbit(((tval >> j) & 1) ^ swapped);
    }
	}
}
#include "decoder.h"
#include "decoderlib.h"
#include<bits/stdc++.h>
using namespace std;
int ptr = 0, cnt[1000], rdh[64][256];
int getbit(){
	if(cnt[ptr] > 0){
		cnt[ptr]--;
		return 1;
	}
	ptr++;
	return 0;
}
void decode(int n, int l, int x[]){
	mt19937 rng(36);
	for(int i = 0; i < n; i++){
    iota(rdh[i], rdh[i] + 256, 0);
    shuffle(rdh[i], rdh[i] + 256, rng);
	}
	memset(cnt, ptr = 0, sizeof(cnt));
	for(int i = 0; i < l; i++){
    cnt[x[i]]++;
  }
	int swapped = getbit();
	for(int i = 0; i < n; i++){
		int val = 0;
		for(int j = 0; j < 8; j++){
			val |= (getbit() ^ swapped) << j;
		}
		output(find(rdh[i], rdh[i] + 256, val) - rdh[i]);
	}
}
#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...