#include "encoder.h"
#include "encoderlib.h"
#include<bits/stdc++.h>
using namespace std;
#define vt vector
#define pb push_back
#define X first
#define Y second
using pii = pair<int,int>;
#define debug(x) do\
{auto _x=x; cerr<<#x<<" = "<<_x<<'\n';}while(0);
#define f0r(i,a,b) for(auto i=(a);i<(b);i++)
#define r0f(i,a,b) for(auto i=(a);i>=(b);i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
// Bash out all the bits???
// Encode the first 2 position bits in the number of send times
// Encode the next 3 in the actual number [7,6,5]
// Encode the head/tail bit in actual number [4]
// use bit tricks to find head and tail
// Potential bug: zeroes in times
void mysend(int a, int times) {
f0r(i,0,times) send(a);
}
void encode(int N, int M[]) {
f0r(pos,0,N) {
int times = (pos >> 3) + 1;
int body = ((pos & ((1 << 3) - 1)) << 5);
int head = M[pos] >> 4;
int tail = M[pos] & ((1 << 4) - 1);
mysend(body | (1 << 4) | head, times);
mysend(body | tail, times);
}
}
#include "decoder.h"
#include "decoderlib.h"
#include<bits/stdc++.h>
using namespace std;
#define vt vector
#define pb push_back
#define X first
#define Y second
using pii = pair<int,int>;
#define debug(x) do\
{auto _x=x; cerr<<#x<<" = "<<_x<<'\n';}while(0);
#define f0r(i,a,b) for(auto i=(a);i<(b);i++)
#define r0f(i,a,b) for(auto i=(a);i>=(b);i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
//potential bug: confusion between N and L
void decode(int d_sz, int N, int xs[]) {
vt<int> freq (255);
vt<int> ans (d_sz);
f0r(i,0,N) {
freq[xs[i]]++;
}
f0r(a,0,255) if(freq[a]) { //BUG : need to check if 0 times
int times = freq[a] - 1; //First 2 position bits
int nt = a >> 5; //Next 3 position bits
bool is_heads = !!(a & (1 << 4));
int block = a & ((1 << 4) - 1);
int where = (times << 3) + nt;
if(is_heads) {
ans[where] += block << 4;
} else {
ans[where] += block;
}
}
f0r(i,0,d_sz) {
output(ans[i]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1328 KB |
Error : Output is wrong |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1336 KB |
Error : Output is wrong |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1332 KB |
Error : Output is wrong |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1344 KB |
Error : Output is wrong |
2 |
Incorrect |
2 ms |
1372 KB |
Error : Output is wrong |
3 |
Incorrect |
3 ms |
1372 KB |
Error : Output is wrong |
4 |
Incorrect |
5 ms |
1400 KB |
Error : Output is wrong |
5 |
Incorrect |
11 ms |
1968 KB |
Error : Output is wrong |
6 |
Incorrect |
11 ms |
1648 KB |
Error : Output is wrong |
7 |
Incorrect |
8 ms |
1444 KB |
Error : Output is wrong |