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<cmath>
#include<cstdio>
bool a[9];
void encode(int N, int M[])
{
int sum=0;
// printf("hebele\n");
for(int i=0; i<N; i++) {
for(int b=0; b<9; b++) a[b] = false;
int n = M[i];
int msg=i;
// printf("%d sayi var i=%d\n",N, i);
msg = msg<<2;
// printf("msg %d\n", msg);
//n sayisi ikilik tabana donusturule
for(int j=7; j>-1; j--) {
if( n>=(1<<j) ) {
a[j] = true;
// printf("%d true\n", j);
n-=1<<j;
}
}
for(int j=0; j<4; j++) {
if(a[2*j] and a[2*j+1]) { sum+=3; }
else if(a[2*j]) { sum+=1;}
else if(a[2*j+1]) {sum+=2;}
}
}
bool v = 0;
for(int i=0; i<N; i++) {
for(int b=0; b<9; b++) a[b] = false;
int n = M[i];
int msg=i;
// printf("%d sayi var i=%d\n",N, i);
msg = msg<<2;
// printf("msg %d\n", msg);
//n sayisi ikilik tabana donusturule
for(int j=7; j>-1; j--) {
if( n>=(1<<j) ) {
a[j] = true;
// printf("%d true\n", j);
n-=1<<j;
}
}
//printf("hebele\n");
if(sum> (6*N)) {
// printf("hebele\n");
int sen=4;
if( !v )send(255); send(255); send(255); send(255);
v = 1;
for(int j=0; j<4; j++) {
if(!(a[2*j] or a[2*j+1]) ) { /*printf("%d 3 kere\n", j); */send(msg+j); send(msg+j); send(msg+j); sen+=3;}
else if(a[2*j] and a[2*j+1]) continue;
else if(a[2*j]) { send(msg+j); send(msg+j); /*printf("%d 2 kere\n", j);*/ sen+=2;}
else if(a[2*j+1]) {/*printf("%d 1 kere\n", j); */send(msg+j); sen++;}
}
// printf("%d kere yollandi\n",sen);
}
else for(int j=0; j<4; j++) {
if(a[2*j] and a[2*j+1]) { /*printf("%d 3 kere\n", j);*/ send(msg+j); send(msg+j); send(msg+j); }
else if(a[2*j]) { send(msg+j); /*printf("%d 1 kere\n", j); */}
else if(a[2*j+1]) {/*printf("%d 2 kere\n", j); */send(msg+j); send(msg+j); }
}
}
/*int i;
for(i=0; i<N; i++)
send(M[i]);*/
}
#include "decoder.h"
#include "decoderlib.h"
#include<cmath>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
int as[66][6];
int ctr;
void decode(int N, int L, int X[])
{
for(int i=0; i<66; i++) for(int j=0; j<6;j++) as[i][j] = 0;
ctr = 0;
for(int i=0; i<L; i++) if(X[i]==255) ctr++;
if(ctr>3) {
for(int i=0; i<66; i++) for(int j=0; j<6;j++) as[i][j] = 3;
for(int i=0; i<L; i++) {
int n = X[i];
n = n>>2;
int k = X[i]%4;
as[n][k]--;
// printf("%d . sayinin %d . bit ikilisi\n", n, k);
}
as[63][3]+=4;
}
else {
for(int i=0; i<66; i++) for(int j=0; j<6;j++) as[i][j] = 0;
for(int i=0; i<L; i++) {
// if(X[i]==255) ctr++; //63 3
// printf("kod %d\n", X[i]);
int n = X[i];
n = n>>2;
int k = X[i]%4;
as[n][k]++;
// printf("%d . sayinin %d . bit ikilisi\n", n, k);
}
}
for(int i=0; i<N; i++) {
int msg = 0;
for(int j=0; j<4; j++) msg+= as[i][j]*pow(2,2*j);
output(msg);
// printf("%d\n", msg);
}
//int i, b;
}
Compilation message (stderr)
encoder.cpp: In function 'void encode(int, int*)':
encoder.cpp:57:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if( !v )send(255); send(255); send(255); send(255);
^~
encoder.cpp:57:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if( !v )send(255); send(255); send(255); send(255);
^~~~
# | 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... |