This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "encoder.h"
#include "encoderlib.h"
#include <bits/stdc++.h>
using namespace std;
bool zero = false;
void solve(int k, int i){
vector<int> bit(8, 0);
for(int i=0; i<8; i++){
if(k & (1 << i)){
bit[i] = 1;
}
}
vector<int> pair;
if(zero){
// mando quando ta desligado
for(int j=0; j<8; j+=2){
if(!bit[j] && !bit[j + 1]) pair.push_back(3);
if(bit[j] && !bit[j + 1]) pair.push_back(2);
if(!bit[j] && bit[j + 1]) pair.push_back(1);
if(bit[j] && bit[j + 1]) pair.push_back(0);
}
} else{
for(int j=0; j<8; j+=2){
if(!bit[j] && !bit[j + 1]) pair.push_back(0);
if(bit[j] && !bit[j + 1]) pair.push_back(1);
if(!bit[j] && bit[j + 1]) pair.push_back(2);
if(bit[j] && bit[j + 1]) pair.push_back(3);
}
}
for(int j=0; j<pair[0]; j++){
send(i * (1 << 2) + 0);
}
for(int j=0; j<pair[1]; j++){
send(i * (1 << 2) + 1);
}
for(int j=0; j<pair[2]; j++){
send(i * (1 << 2) + 2);
}
for(int j=0; j<pair[3]; j++){
send(i * (1 << 2) + 3);
}
}
void encode(int n, int m[]){
int cnt_zero = 4, cnt_one = 0;
for(int i=0; i<n; i++){
vector<int> bit(8, 0);
for(int j=0; j<8; j++){
if(m[i] & (1 << j)){
bit[j] = 1;
}
}
for(int j=0; j<8; j+=2){
if(!bit[j] && !bit[j + 1]) cnt_zero += 3;
if(!bit[j] && bit[j + 1]) cnt_zero += 2, cnt_one ++;
if(bit[j] && !bit[j + 1]) cnt_zero += 1, cnt_one += 2;
if(bit[j] && bit[j + 1]) cnt_one += 3;
}
}
if(cnt_one > cnt_zero){
zero = true;
for(int i=0; i<4; i++) send(0);
}
for(int i=0; i<n; i++){
solve(m[i], i);
}
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
using namespace std;
void decode(int n, int l, int x[]){
vector<vector<int>> id(n);
// cout << "decode\n";
int cnt_zero = 0;
bool zero = false;
for(int i=0; i<l; i++){
if(x[i] == 0) cnt_zero ++;
}
if(cnt_zero >= 4) zero = true;
for(int i=0; i<l; i++){
id[x[i] >> 2].push_back(x[i] % 4);
}
if(zero){
for(int i=0; i<n; i++){
vector<int> pair(4, 0);
if(!id[i].empty()){
for(auto k : id[i]){
pair[k] ++;
}
}
if(zero && i == 0) pair[0] -= 4;
int ans = 0;
for(int j=0; j<4; j++){
if(pair[j] == 2) ans += (1 << (2 * j));
if(pair[j] == 1) ans += (1 << (2 * j + 1));
if(pair[j] == 0) ans += (1 << (2 * j)) + (1 << (2 * j + 1));
}
output(ans);
}
} else{
for(int i=0; i<n; i++){
vector<int> pair(4, 0);
if(!id[i].empty()){
for(auto k : id[i]){
pair[k] ++;
}
}
int ans = 0;
for(int j=0; j<4; j++){
if(pair[j] == 1) ans += (1 << (2 * j));
if(pair[j] == 2) ans += (1 << (2 * j + 1));
if(pair[j] == 3) ans += (1 << (2 * j)) + (1 << (2 * j + 1));
}
output(ans);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |