# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
250514 | kostia244 | Parrots (IOI11_parrots) | C++17 | 0 ms | 0 KiB |
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 "decoder.h"
#include "decoderlib.h"
#include<bits/stdc++.h>
using namespace std;
void decode(int n, int l, int X[]) {
vector<int> res(n);
map<int, int> cnt;
for(int i = 0; i < l; i++) cnt[X[i]]++;
vector<int> G = {0, 1, 2, 3};
for(auto i : cnt) {
if(i.second >= n) {
i.second -= n;
while(i.second--) next_permutation(G.begin(), G.end());
}
}
//for(auto i : G) cout << i << " "; cout << '\n';
for(int i = 0; i < 255; i++) {
if(i/4 >= res.size()) break;
if(cnt[i] >= n) cnt[i] = 0;
res[i/4] += G[cnt[i]]<<(2*(i&3));
}
//for(int i = 0; i < n; i++) cout << res[i] << '\n';
for(int i = 0; i < n; i++) output(res[i]);
}
#include "encoder.h"
#include "encoderlib.h"
#include<bits/stdc++.h>
using namespace std;
int ord(vector<array<int, 2>> g) {
int o = 0, f = 1;
for(int i = 0; i < g.size(); i++) {
f = 1;
for(int j = 1; j < g.size()-i; j++) f *= j;
int s = 0;
for(int j = i; j < g.size(); j++) s += g[j][1] < g[i][1];
o += s*f;
}
//for(int i = 0; i < g.size(); i++) cout << g[i][1] << " ";cout << " : " << o << '\n';
return o;
}
void encode(int n, int b[]) {
map<int, int> m;
for(int i = 0; i < n; i++) {
int t = b[i], g = 0;
for(int g = 0; g < 4; g++) {
m[4*i + g]+=(t&3);
t>>=2;
}
}
map<int, int> ff;
for(auto [x, y] : m) ff[y]++;
vector<array<int, 2>> g;
for(int i = 0; i < 4; i++) g.push_back(array<int, 2>{ff[i], i});
sort(g.rbegin(), g.rend());
//swap(g[0], g[1]);
map<int, int> c;
for(int i = 0; i < g.size(); i++) c[g[i][1]] = i;
int empt = 0;
for(auto [i, f] : m) {
//cout << f << " to ";
f = c[f];
//cout << c[f] << '\n';
if(!f) empt = i;
while(f--) send(i);
}
for(int i = n + ord(g); i--;) send(empt);
}