Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include "librero.h"
- using namespace std;
- #define MOD 1000000007
- long long factorial(long long n)
- {
- long long f = 1;
- for(long long i=1; i<=n; i++)
- f = f*i%MOD;
- return f;
- }
- vector <int> librero(vector <int> bases, vector <int> libros, vector <int> &orden)
- {
- map<int, int> mapBases, mapLibros;
- for(int i=0; i<(int)bases.size(); i++)
- {
- mapBases[bases[i]]++;
- mapLibros[libros[i]]++;
- }
- if(mapBases.size() != mapLibros.size())
- return {-1, 0};
- auto itBases = mapBases.begin();
- auto itLibros = mapLibros.rbegin();
- long long formas = 1;
- int alturaRef = itBases->first + itLibros->first;
- for(int i=0; i<(int)mapBases.size(); i++)
- {
- if(itBases->first + itLibros->first != alturaRef)
- return {-1, 0};
- if(itBases->second != itLibros->second)
- return {-1, 0};
- formas = formas*factorial(itLibros->second)%MOD;
- itBases++, itLibros++;
- }
- vector <pair<int, int> > parBases(bases.size()), parLibros(libros.size());
- for(int i=0; i<(int)bases.size(); i++)
- {
- parBases[i] = {bases[i], i};
- parLibros[i] = {libros[i], i};
- }
- sort(parBases.rbegin(), parBases.rend());
- sort(parLibros.begin(), parLibros.end());
- orden.resize(bases.size());
- for(int i=0; i<(int)parBases.size(); i++)
- orden[parBases[i].second] = parLibros[i].second+1;
- return {alturaRef, (int)formas};
- }
Advertisement
Add Comment
Please, Sign In to add comment