Submission #250519

#TimeUsernameProblemLanguageResultExecution timeMemory
250519kostia244Parrots (IOI11_parrots)C++17
81 / 100
16 ms1792 KiB
#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 st = 0;
	for(auto [i, f] : m) {
		//cout << f << " to ";
		f = c[f];
		//cout << c[f] << '\n';
		while(f--) send(i), st++;
	}
	for(int t = ord(g), i = 4; i--;) send(t);
}
#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 >= 4) {
			int f = i.first;
			while(f--) 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] >= 4) cnt[i] -= 4;
		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]);
}

Compilation message (stderr)

encoder.cpp: In function 'int ord(std::vector<std::array<int, 2> >)':
encoder.cpp:7:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < g.size(); i++) {
                 ~~^~~~~~~~~~
encoder.cpp:9:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 1; j < g.size()-i; j++) f *= j;
                  ~~^~~~~~~~~~~~
encoder.cpp:11:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = i; j < g.size(); j++) s += g[j][1] < g[i][1];
                  ~~^~~~~~~~~~
encoder.cpp: In function 'void encode(int, int*)':
encoder.cpp:20:17: warning: unused variable 'g' [-Wunused-variable]
   int t = b[i], g = 0;
                 ^
encoder.cpp:27:16: warning: unused variable 'x' [-Wunused-variable]
  for(auto [x, y] : m) ff[y]++;
                ^
encoder.cpp:33:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < g.size(); i++) c[g[i][1]] = i;
                 ~~^~~~~~~~~~

decoder.cpp: In function 'void decode(int, int, int*)':
decoder.cpp:19:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(i/4 >= res.size()) break;
      ~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...