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 <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <utility>
#include <string>
using namespace std;
vector<vector<int> > gen_nk_sets (int n, int k){
//Generates all sets of size n containing only 0 to k-1.
vector<vector<int> > sets;
if (k == 1){
vector<int> single (n, 0);
sets.push_back(single);
return sets;
}
if (n == 0){
vector<int> emptyset(0, 0);
sets.push_back(emptyset);
return sets;
}
vector<vector<int> > reduced_1 = gen_nk_sets(n - 1, k);
sets = gen_nk_sets(n, k - 1);
for (int i = 0; i < reduced_1.size(); i++){
reduced_1[i].push_back(k - 1);
sets.push_back(reduced_1[i]);
}
return sets;
}
void encode(int N, int M[])
{
vector<bool> message;
for(int i = 0; i < N; i++){
for (int j = 7; j >= 0; j--){
message.push_back((M[i] & (1 << j)));
}
}
// for (int i = 0; i < N; i++){
// cout << M[i] << ' ';
// }
// cout << endl;
//
// for (int i = 0; i < message.size(); i++){
// cout << message[i] << ' ';;
// }
// cout << endl;
vector<vector<int> > s5 = gen_nk_sets(5, 4);
vector<vector<int> > s6 = gen_nk_sets(6, 4);
vector<vector<int> > s7 = gen_nk_sets(7, 4);
int size5 = 56;
int size6 = 84;
int size7 = 120;
for (int i = 0; i < N; i++){
int to_send = M[i];
vector<int> send_array;
if (to_send < size5){
send_array = s5[to_send];
}else{
to_send -= size5;
if (to_send < size6){
send_array = s6[to_send];
} else {
to_send -= size6;
send_array = s7[to_send];
}
}
for (int j = 0; j < send_array.size(); j++){
//cout << 's' << 4 * i + send_array[j] << endl;
send(4 * i + send_array[j]);
}
}
}
#include "decoder.h"
#include "decoderlib.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <utility>
using namespace std;
vector<vector<int> > gen_nk_sets2 (int n, int k){
//Generates all sets of size n containing only 0 to k-1.
vector<vector<int> > sets;
if (k == 1){
vector<int> single (n, 0);
sets.push_back(single);
return sets;
}
if (n == 0){
vector<int> emptyset(0, 0);
sets.push_back(emptyset);
return sets;
}
vector<vector<int> > reduced_1 = gen_nk_sets2(n - 1, k);
sets = gen_nk_sets2(n, k - 1);
for (int i = 0; i < reduced_1.size(); i++){
reduced_1[i].push_back(k - 1);
sets.push_back(reduced_1[i]);
}
return sets;
}
void decode(int N, int L, int X[])
{
vector<pair<int, int> > recieved;
vector<int> full_recieved;
for(int i=0; i<L; i++) {
recieved.push_back(make_pair(X[i] >> 2, X[i] & 3));
}
sort(recieved.begin(), recieved.end());
vector<vector<int> > s5 = gen_nk_sets2(5, 4);
vector<vector<int> > s6 = gen_nk_sets2(6, 4);
vector<vector<int> > s7 = gen_nk_sets2(7, 4);
int size5 = 56;
int size6 = 84;
int size7 = 120;
vector<vector<int> > groupings (N, vector<int>());
for (int i = 0; i < recieved.size(); i++){
groupings[recieved[i].first].push_back(recieved[i].second);
}
for (int i = 0; i < N; i++){
for (int j = 0; j < s5.size(); j++){
if (groupings[i] == s5[j]){
output(j);
}
}
for (int j = 0; j < s6.size(); j++){
if (groupings[i] == s6[j]){
output(j + size5);
}
}
for (int j = 0; j < s7.size(); j++){
if (groupings[i] == s7[j]){
output(j + size5 + size6);
}
}
}
}
Compilation message (stderr)
encoder.cpp: In function 'std::vector<std::vector<int> > gen_nk_sets(int, int)':
encoder.cpp:38:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < reduced_1.size(); i++){
~~^~~~~~~~~~~~~~~~~~
encoder.cpp: In function 'void encode(int, int*)':
encoder.cpp:106:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < send_array.size(); j++){
~~^~~~~~~~~~~~~~~~~~~
encoder.cpp:77:9: warning: unused variable 'size7' [-Wunused-variable]
int size7 = 120;
^~~~~
decoder.cpp: In function 'std::vector<std::vector<int> > gen_nk_sets2(int, int)':
decoder.cpp:37:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < reduced_1.size(); i++){
~~^~~~~~~~~~~~~~~~~~
decoder.cpp: In function 'void decode(int, int, int*)':
decoder.cpp:67:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < recieved.size(); i++){
~~^~~~~~~~~~~~~~~~~
decoder.cpp:76:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < s5.size(); j++){
~~^~~~~~~~~~~
decoder.cpp:82:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < s6.size(); j++){
~~^~~~~~~~~~~
decoder.cpp:88:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < s7.size(); j++){
~~^~~~~~~~~~~
decoder.cpp:63:9: warning: unused variable 'size7' [-Wunused-variable]
int size7 = 120;
^~~~~
# | 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... |