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;
}
}
// cout << zero << endl;
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);
// cout << 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);
// cout << i * (1 << 2) + 0 << " ";
}
// cout << ", ";
for(int j=0; j<pair[1]; j++){
send(i * (1 << 2) + 1);
// cout << i * (1 << 2) + 1 << " ";
}
// cout << ", ";
for(int j=0; j<pair[2]; j++){
send(i * (1 << 2) + 2);
// cout << i * (1 << 2) + 2 << " ";
}
for(int j=0; j<pair[3]; j++){
send(i * (1 << 2) + 3);
// cout << i * (1 << 2) + 3 << " ";
}
// cout << endl;
}
void encode(int n, int m[]){
int cnt_zero = 0, 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_one ++, cnt_zero += 2;
if(bit[j] && !bit[j + 1]) cnt_one += 2, cnt_zero ++;
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);
// cout << 0 << " ";
}
}
// cout << zero << endl;
for(int i=0; i<n; i++){
// cout << "solve " << m[i] << " " << i << ":\n";
solve(m[i], i);
}
// cout << endl;
}
#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;
cnt_zero = 0;
for(int i=0; i<l; i++){
if(zero && x[i] == 0 && cnt_zero < 4){
cnt_zero ++;
continue;
}
id[x[i] >> 2].push_back(x[i] % 4);
}
// cout << zero << endl;
// cout << "decode\n";
if(zero){
for(int i=0; i<n; i++){
vector<int> pair(4, 0);
// cout << i << ": ";
for(auto k : id[i]){
pair[k] ++;
// cout << k << " ";
}
// cout << endl;
int ans = 0;
for(int j=0; j<4; j++){
// cout << j << " " << pair[j] << endl;
if(pair[j] == 2) ans += (1 << (2 * j + 1));
if(pair[j] == 1) ans += (1 << (2 * j));
if(pair[j] == 0) ans += (1 << (2 * j)) + (1 << (2 * j + 1));
}
cout << ans << endl;
output(ans);
}
return;
}
for(int i=0; i<n; i++){
vector<int> pair(4, 0);
// cout << i << ": ";
for(auto k : id[i]){
pair[k] ++;
// cout << k << " ";
}
// cout << endl;
int ans = 0;
for(int j=0; j<4; j++){
if(pair[j] == 1) ans += (1 << (2 * j + 1));
if(pair[j] == 2) ans += (1 << (2 * j));
if(pair[j] == 3) ans += (1 << (2 * j)) + (1 << (2 * j + 1));
}
// cout << ans << endl;
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... |